Write LEGv8 "shift assembly instruction" to achieve the multiplication of a binary number by 16
Solution:
to_binary PROC
push BX ; save registers
push CX
push DX
xor AX,AX ; result := 0
mov CX,4 ; max. number of octal
digits
repeat1:
; loop itarates a maximum of 3 times;
; but a NULL can terminates it early
mov DL,[BX] ; read the octal
digit
cmp DL,0 ; is it NULL?
je finished ; if so, terminate loop
and DL,0FH ; else, convert char. to numeric
shl AL,4 ; multiply by 16 and add to binary
add AL,DL
inc BX ; move to next octal digit
loop repeat1 ; and repeat
finished:
pop DX ; restore registers
pop CX
pop BX
ret
to_binary ENDP
END main
Get Answers For Free
Most questions answered within 1 hours.