Hi, in trying multiplicate in decimal 300 x 300 an then print the result on screen. first two multiplications worked well but I'm stuck in the last one because the result of the multiplication is stored at AX and DX. Is there anything i can do to manipulate those two registers as if it was one in order to be able to convert that hex result in decimal usind the DecimalToString proc in the code?
This code is for 8086 and I'm using emu8086 to run the code.
here is a picture that highlights the hex values in ax and dx that i need to change hex to dec.
here is the code
This code is for 8086 and I'm using emu8086 to run the code.
here is a picture that highlights the hex values in ax and dx that i need to change hex to dec.
here is the code
Rich (BB code):
;multiplicacion
org 100h
.model small
.stack 100h
CR equ 13d
LF equ 10d
.data
mult1 db "byte1 * byte2= (5*10)= $"
mult2 db CR, LF, "byte1 * word1= (350*10)= $"
mult3 db CR, LF, "word1 * word2= (300*300)= $"
.code
start:
mov ax, @data
mov ds, ax
mov dx, offset mult1
call puts ; llama subprograma llamado puts
;---- byte * byte -----
mov bl, 5
mov cl, 10
mov al, cl
mul bl
call DecimalToString ;llama el procedimiento que convierte un numero decimal en un string y lo imprime en pantalla
;---- byte * word -----
mov dx, offset mult2
call puts
mov bx, 350
mov cx, 10
mov ax, cx
mul bx
call DecimalToString
;---- word * word -----
mov dx, offset mult3
call puts
mov bx, 300
mov cx, 300
mov ax, cx
mul bx
call DecimalToString
mov ah, 4ch ;termina el programa int 21h
int 21h
;----- hex to dec -----
DecimalToString PROC ;comienza el procedimiento
push ax ;salvando ax, bx, cx, dx en el stack
push bx
push cx
push dx
xor cx, cx ;basicamente hace esto: cx = 00000000
mov bx, 10d ;pone el decimal 10 en bx
loop1:
xor dx, dx ;hace esto: dx = 00000000
div bx ;divide ax por bx y pone el resultado en dx
push dx ;guarda el residuo en el stack
inc cx ;cuenta el numero de residuos guardados en el stack
cmp ax, 0 ;divide hasta que ax = 0
jnz loop1 ;loop hasta ax = 0
mov ah, 02 ;parametro para int 21
loop2:
pop dx ;nos da el ultimo valor de dx guardado en el stack
add dl, 48 ;suma 48 porque 48 es el ASCII code de cero (0)
int 21h ;llama el int 21 para imprimir valor en dx
dec cx ;disminuye el conteo de residuos
jnz loop2
pop dx ;devuelve los valores originales en los registros
pop cx
pop bx
pop ax
ret
DecimalToString ENDP ;termina el procedimiento
ret
mov ax, 4c00h
int 21h ; return to ms-dos
; user defined subprograms
puts: ; display a string terminated by $
mov ah, 9h
int 21h
ret
putc: ; display character in dl
mov ah, 2h
int 21h
ret
Attachments
-
86.5 KB Views: 10