transfer to xlatb instruction number_to_convert db 0A7h number_converted_to_ASCI
ID: 1800218 • Letter: T
Question
transfer to xlatb instructionnumber_to_convert db 0A7h
number_converted_to_ASCII db 0, 0
hex_table db '0123456789ABCDEF'
pkey db "press any key...$"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
;Modify the code given below to use the xlatb instruction
mov al,number_to_convert ;Read value to convert and convert least significant digit
and al,00001111b ;Mask hex value
mov bx,0
mov bl,al
mov al,hex_table[bx] ;Convert
mov number_converted_to_ASCII+1,al ;Store converted value
mov al,number_to_convert ;Read value to convert and convert most significant digit
and al,11110000b ;Mask hex value
mov cl,4
shr al,cl
mov bx,0
mov bl,al
mov al,hex_table[bx] ;Convert
mov number_converted_to_ASCII,al ;Store converted value
;End of modifyable code
Explanation / Answer
xlat_string proc src:DWORD,ln:DWORD,tbl:DWORD push ebx mov edx, src ; string address in ESI mov ebx, tbl ; character table in EBX mov ecx, ln ; string length in ECX add edx, ecx ; add length to ESI neg ecx ; invert sign and use ECX as index @@: mov al, [edx+ecx] ; get byte xlatb ; swap it with byte in table mov [edx+ecx], al ; write it back to the same place inc ecx jnz @B ; jump back if less than zero pop ebx ret xlat_string endp ; ????????????????????????????????????????????????????????????????????????? STRING tststr,"This is a test !!!!" jmp @F align 4 The_Table: db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 db 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 db 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47 db 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63 db 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79 db 80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95 db 96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111 db 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127 @@: lea eax, The_Table invoke xlat_string,ADDR tststr,19,eax invoke MessageBox,hWin,ADDR tststr, ADDR szDisplayName,MB_OK
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.