Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

dec to hex

stevem222stevem222 Member Posts: 24
I am stuck on this program in which I have to enter a positive number (up to 5 digits), and then get it's hex equivalent. I have written some ideas up, but they do not seem to flow when I go to writing the code. See below:

move 0 to ax
save current product
get next digit character
validate as 0-9
if not valid, call display
convert to digit
move value into cx
retrieve current product
move 10 into bl
multily by 10 (bl)
add cx, ax
pop ax
call display

Now, I believe I am on the right track. This brings me to getting stuck on the conversion portion, which can be seen in the large blank space in my head (I mean, code). Your past help and current help is greatly appreciated. I am in a class in which the book is MASM, the teacher assigns programs which are TASM, gives no practice assignments in which I can exercise enough to know this stuff, etc.

Here is what I have chicken-poked in. NOTE: There is a blank space (I am aware) where I will need a subproc.

.model small
.stack 100h
.data

prompt db 10,13, 'Enter a positive integer: $'
outmes db 10,13, 'Hex euivalent is: $'
sax dw 0

.code

conv proc
mov ax, @data
mov ds, ax
disp:
mov dx, offset prompt
mov ah, 9h
int 21h

mov ax,0

getdec:
mov ah, 1ah
int 21h

cmp al, 13
je goon

goon:
mov ah, 0
sub ax, 30h
push ax


mov cx, ax

pop ax
mov bl, 10
mul bl
add cx, ax
pop ax

mov ah, 09h
int 21h

mov ah, 4ch
int 21h

conv endp





end conv

Comments

  • nastinatornastinator Member Posts: 19
    [b][red]This message was edited by nastinator at 2002-10-25 4:52:16[/red][/b][hr]
    : I am stuck on this program in which I have to enter a positive number (up to 5 digits), and then get it's hex equivalent. I have written some ideas up, but they do not seem to flow when I go to writing the code. See below:
    :
    : move 0 to ax
    : save current product
    : get next digit character
    : validate as 0-9
    : if not valid, call display
    : convert to digit
    : move value into cx
    : retrieve current product
    : move 10 into bl
    : multily by 10 (bl)
    : add cx, ax
    : pop ax
    : call display
    :
    : Now, I believe I am on the right track. This brings me to getting stuck on the conversion portion, which can be seen in the large blank space in my head (I mean, code). Your past help and current help is greatly appreciated. I am in a class in which the book is MASM, the teacher assigns programs which are TASM, gives no practice assignments in which I can exercise enough to know this stuff, etc.
    :
    : Here is what I have chicken-poked in. NOTE: There is a blank space (I am aware) where I will need a subproc.
    :
    : .model small
    : .stack 100h
    : .data
    :
    : prompt db 10,13, 'Enter a positive integer: $'
    : outmes db 10,13, 'Hex euivalent is: $'
    : sax dw 0
    :
    : .code
    :
    : conv proc
    : mov ax, @data
    : mov ds, ax
    : disp:
    : mov dx, offset prompt
    : mov ah, 9h
    : int 21h
    :
    : mov ax,0
    :
    : getdec:
    : mov ah, 1ah
    : int 21h
    :
    : cmp al, 13
    : je goon
    :
    : goon:
    : mov ah, 0
    : sub ax, 30h
    : push ax
    :
    :
    : mov cx, ax
    :
    : pop ax
    : mov bl, 10
    : mul bl
    : add cx, ax
    : pop ax
    :
    : mov ah, 09h
    : int 21h
    :
    : mov ah, 4ch
    : int 21h
    :
    : conv endp
    :
    :
    :
    :
    :
    : end conv
    :
    :
    try moving 16 into register (the register that holds the number)
    ex. ax = 9 ;register holds the decimal value of 9
    mov bx,16 ;convert to hexidecimal (radix of hexidecimal)
    int 21h ;display to screen

    I am just learning the lanuage, but this should work


  • Andre YoungAndre Young USAMember Posts: 0

    [ http://forcoder.org ] free ebooks and video tutorials about < C, PHP, MATLAB, Visual Basic .NET, Go, R, C#, Perl, Swift, Delphi, Ruby, Visual Basic, JavaScript, Python, C++, Scratch, Objective-C, Java, PL/SQL, Assembly Lua, Fortran, D, Ada, Dart, Crystal, Kotlin, Scheme, Logo, Clojure, Awk, Prolog, FoxPro, LabVIEW, Julia, COBOL, Rust, Hack, Scala, ABAP, Apex, F#, SAS, ML, Transact-SQL, VBScript, Lisp, Erlang, Bash, Alice /> _____________

Sign In or Register to comment.