How do I display the result and remainder in ax and dx in Assembly (tasm)

2.5k views Asked by At

I have the number 10 divided by 10, I wish to display the values, that are in ax, and dx, but TASM will not allow me to move ax, nor dx, into dl to display them side by side

    .model small
    .stack 100h
    .data
    Integer dw 5h
    Numbre dw 5h
    .code
    Start:
    mov ax,@data
    mov ds,ax
    mov ax,Integer
    mov bx,Numbre
    add ax,bx
    mov cx,10h
    mov dx,0h
    jmp compare
    compare : cmp ax,09
        ja divide
        jbe display_result
    divide : div cx
        add ax,"0"
        add dx,"0"
        jmp display_result_large
    display_result : add ax,"0"
        mov dl,ax
        mov ah,2h
        int 21h
        jmp endall
    display_result_large : mov dl,ax
        mov ah,2h
        int 21h
        mov dl,dx
        mov ah,2h
        int 21h
        jmp endall
    endall : mov ah,4ch
        int 21h
        end Start
1

There are 1 answers

7
Michael On BEST ANSWER

dl is an 8-bit register - ax and dx are 16-bit registers. You can access the low and high byte of ax as al and ah, and of dx as dl and dh. So instead of mov dl, ax you should use mov dl,al.

The instruction mov dl,dx would be replaced by mov dl,dl, but that would be a pointless operation. However, since you changed dl's value when you did mov dl,al you'll have to save and restore it somehow. The easiest way would be to use the stack:

display_result_large :
    push dx    ; save dx on the stack
    mov dl,al
    mov ah,2h
    int 21h
    pop dx    ; restore dx's old value. the low byte of dx is dl, so
              ; the character is already in the correct register.
    mov ah,2h
    int 21h
    jmp endall