07-24-2023, 12:25 PM
I am somewhat new to assembly language programming so pardon me if this question seems irrelevant.
I was trying to understand a 32-bit addition program and following is one of the procedures used to display the result of addition (saved in EAX) back to console:
;Procedure to display EAX as a 8 digit hex number
DISPH PROC NEAR
PUSH EBX ; Save EBX
MOV CL,4 ; To rotate the register by 4 bits
MOV SI,8 ; Count for displaying 8 digits
DISPH1:
ROL EAX,CL ; Rotate EAX left by 4 bits
PUSH EAX ; Save EAX
AND AL,0FH
ADD AL,30H
CMP AL,'9' ; if AL <= '9', AL contains the ASCII code
JBE DISPH2
ADD AL,7 ; if AL > '9' , add 07H to AL to convert into ASCII
DISPH2:
MOV AH,2H ; O/P subprogram
MOV DL,AL ; Call MS-DOS O/P subprogram
INT 21H ; Display the data in DL register on screen
POP EAX ; retrieve EAX from Stack
DEC SI
JNZ DISPH1
POP EBX ; Restore EBX
RET
DISPH ENDP
END ; end of file
Please help me understand why the ROL instruction is used under DISP1 label, and what does it achieve.
Thanks in advance. :)
I was trying to understand a 32-bit addition program and following is one of the procedures used to display the result of addition (saved in EAX) back to console:
;Procedure to display EAX as a 8 digit hex number
DISPH PROC NEAR
PUSH EBX ; Save EBX
MOV CL,4 ; To rotate the register by 4 bits
MOV SI,8 ; Count for displaying 8 digits
DISPH1:
ROL EAX,CL ; Rotate EAX left by 4 bits
PUSH EAX ; Save EAX
AND AL,0FH
ADD AL,30H
CMP AL,'9' ; if AL <= '9', AL contains the ASCII code
JBE DISPH2
ADD AL,7 ; if AL > '9' , add 07H to AL to convert into ASCII
DISPH2:
MOV AH,2H ; O/P subprogram
MOV DL,AL ; Call MS-DOS O/P subprogram
INT 21H ; Display the data in DL register on screen
POP EAX ; retrieve EAX from Stack
DEC SI
JNZ DISPH1
POP EBX ; Restore EBX
RET
DISPH ENDP
END ; end of file
Please help me understand why the ROL instruction is used under DISP1 label, and what does it achieve.
Thanks in advance. :)