-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathv_hex1.txt
32 lines (27 loc) · 1.1 KB
/
v_hex1.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
; Subroutine v_hex1 displays one byte in hexadecimal.
; R12: Points to the byte in memory
; Registers preserved: RBX,RBP,RDI,RSI,RSP,R12-R15
v_asc proto ; Declare external subroutine.
.code
v_hex1 proc ; Subroutine v_bin1 entry point
push RBX ; Save RBX and decrement RSP by 8
lea RDX,nib2 ; Points to 2-byte memory buffer
lea RBX,dig ; Pointer to list of hex digits
mov AL,[R12] ; Load byte to be displayed
shr AL,4 ; Right justify first nibble
xlat ; Convert 4-bit nibble to hex digit
mov [RDX],AL ; Store high-order hex digit.
mov AL,[R12] ; Reload byte to be displayed
and AL,1111b ; Mask off all but second nibble.
xlat ; Convert 4-bit nibble to hex digit
mov [RDX+1],AL ; Store low-order hex digit.
mov R8,2 ; Number of characters to display
call v_asc ; Subroutine that displays ASCII
pop RBX ; Reload RBX and reposition stack
ret ; Return to the calling program
v_hex1 endp
.data
dig byte "0123456789" ; ASCII string of digits 0 through 9
byte "ABCDEF" ; ASCII string of digits A through F
nib2 byte 2 DUP (?) ; Memory buffer for display
end