| <<< Extended-Precision Integers and Shifting Multiple Doublewords | Index | Assignment: High-speed Multiplication of 32-bit Integer by Powers of 2 >>> |
A good way to apply the shift instructions is to display bytes of ASCII strings in binary format.
For example, if SHL is used,
the highest bit of the operand is copied into the Carry flag each time the byte is shifted to the left.
The following program displays each of the bits in EAX:
.DATA ; Begin data segment
Value DWORD 1234ABCDh ; sample binary value
buffer BYTE 32 dup(0), 0 ; output buffer
.CODE ; Begin code segment
mov eax, Value ; value to display
mov ecx,32 ; number of bits in EAX
mov esi, OFFSET buffer
next_bit:
shl eax, 1 ; shift high bit into Carry flag
mov BYTE PTR [esi], '0' ; display zero by default
jnc next_byte ; if no Carry, advance to next byte
mov BYTE PTR [esi], '1' ; otherwise display 1
next_byte:
inc esi ; next buffer position
loop next_bit ; shift another bit to left
; Display output buffer on the screen...
; ...
| <<< Extended-Precision Integers and Shifting Multiple Doublewords | Index | Assignment: High-speed Multiplication of 32-bit Integer by Powers of 2 >>> |