Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 246 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is ROL instruction used?

#1
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. :)
Reply

#2
The code prints a 32 bit value in hexadecimal. The ROL instruction is convenient here because it lets you process the nibbles in the highest to lowest order.

Consider the value 0xCAFED00D. To print the first four letters it out you have to extract the values 'C' A' 'F' and 'E' in this order.

EAX = 0xCAFED00D

ROL EAX, 4 -> EAX = AFED00DC (lowest nibble is C)
ROL EAX, 4 -> EAX = FED00DCA (lowest nibble is A)
ROL EAX, 4 -> EAX = ED00DCAF (lowest nibble is F)
ROL EAX, 4 -> EAX = D00DCAFE (lowest nibble is E)

and so on..

As you can see this sequence moves the value of interest into the lowest nibble. Extracting this value is done by ANDing the resulting value with 0x0f.

Afterwards the value gets converted into a hexadecimal character and outputted via DOS BIOS.


Reply

#3
It is used to iterate over the digits of the number during the display operation. At each iteration it sets into the lower byte of EAX the bits that correspond to the next digit to display. Unlike SHL/SHR operations, ROL will preserve the original value in the EAX after completion of the entire display routine. ROL is naturally convenient for displaying from the highest digit (similar effect could be achieved by SHR by 32-amount of processed bits, but ROL is more straightforward).
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through