0
$\begingroup$

I'm learning assembly programming and I can't seem to get my head around the register usage, as I'm using emu8086 which emulates old 8086 processors. According to 8086 (16-bit architecture) the four General Purpose Registers are:

General Purpose Registers

My confusion is: why does using DL and DH give different results, as they both are the lower and higher byte registers of DX which is a 16-bit register?

Code 1:

.model small
.stack 100h
.data
.code
main proc  
    mov dl, 'A' 
    mov ah, 2  
    int 21h    
    
    mov dl, 10    ;for next line feed, using lower byte data register
    mov ah, 2
    int 21h  
    
    mov dl, 'B'  
    mov ah, 2  
    int 21h
    
    
endp 
end main

OUTPUT

A
 B

Code 1:

.model small
.stack 100h
.data
.code
main proc  
    mov dl, 'A' 
    mov ah, 2  
    int 21h    
    
    mov dh, 10    ;for next line feed, using higher byte data register
    mov ah, 2
    int 21h  
    
    mov dl, 'B'   
    mov ah, 2  
    int 21h
    
    
endp 
end main

OUTPUT:

AAB
$\endgroup$
2
  • $\begingroup$ Moving $10$ into $dl$ will yield a different value for $dx$ than moving $10$ to $dh$. $\endgroup$
    – nir shahar
    Commented Dec 19, 2021 at 20:51
  • $\begingroup$ I suspect that debugging your assembly code is off-topic here. Coding questions and implementation questions are off-topic here. $\endgroup$
    – D.W.
    Commented Dec 20, 2021 at 4:38

1 Answer 1

1
$\begingroup$

DL and DH are two different registers and they are used for different tasks. In particular, the interrupt you are using, int21 service02, prints to the screen the content of register DL (and ignores DH). See http://spike.scu.edu.au/~barry/interrupts.html#ah02

In your second code fragment, you put 'A' in DL and execute int21, which prints 'A' to the screen. Then you change DH (but not DL! DL='A' still) and execute int21, which, again, prints 'A'.

Note that if you were performing 'MOV DX, 10' this would have changed both DH and DL, and caused the same effect as 'MOV DL,10", in this case. But changing DH only affects the upper part of DX, leaving the lower part, DL, unchanged.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.