moving inputted value to ax register (newbie gets lost)

ok, here's the deal. this program is to display an inputted decimal number to hex and octal and display. I've got two steps away from being done and I hit the wall.

in the sections called 'convert_hex' and 'convert_oct', there's a statement: mov ax, in_buff[2] -> I'm trying to move the inputted value (now converted to decimal from ASCII) to ax to do the conversion to the other number systems. however I know this isn't right (obviously), but I don't know what is! can somebody help with that??

also, if you see something else I don't know about that isn't going to work please tell me. much appreciated. thanks!!!!

.MODEL SMALL
.586

.STACK 100h

.DATA
REQUEST DB 'Please enter a number between 0 and 65535 to convert: $'
HEX DB 'Hex Representation: $'
OCT DB 'Oct Representation: $'
RFeed DB 13, 10, '$'
in_buff DB 04h, 06h dup(00h) ; to hold exactly 16-bits


.CODE
Two PROC

string_input:
mov ax, @data
mov ds, ax; move data to DS register

mov ah, 0ah
mov dx, offset in_buff
int 21h; call for string input

call crlf

mov bx, 0000h
mov cl, 12
mov si, offset in_buff + 2
cmp in_buff[1], 00h
jz string_input

do_char:
mov al, [si]
cmp al, 0Dh
jz convert_hex
sub al, 30h
jb bad_input
cmp al, 09h
ja bad_input
mov ah, 00h
mov cx, ax
mov ax, 000ah
mul bx
jc bad_input
add ax, cx
jc bad_input
mov bx, ax
inc si
jmp do_char

bad_input:
mov ah, 02h
mov dl, 07h
int 21h
jmp string_input

convert_hex:
mov ax, in_buff[2]
shr ax, cl
and al, 000Fh
cmp al, 10
jl under_ten
add al, 'A' - 10
jmp show_hex

under_ten:
add al, 30h

show_hex:
mov ah, 02h
mov dl, al
int 21h
sub cl, 4
inc bx
cmp bx, 4
je reset_for_oct
jmp convert_hex

reset_for_oct:
call crlf
mov bx, 0000h
mov cl, 15

convert_oct:
mov ax, in_buff[2]
shr ax, cl
and al, 07h
add al, 30h

show_oct:
mov ah, 02h
mov dl, al
int 21h
sub cl, 3
inc bx
cmp bx, 6
je done
jmp convert_oct

done:
mov al, 0
mov ah, 4ch
int 21h

two ENDP



crlf PROC

mov dx, OFFSET RFeed
mov ah, 09h
int 21h;
RET

crlf ENDP

END Two

Sign In or Register to comment.

Howdy, Stranger!

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

Categories