Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .text:
- global _start
- _start:
- hex2ascii:
- ; prelude
- push ebp
- mov ebp, esp
- ; stack: [ arg | return address | saved ebp ]
- ; ^ ebp + 8 ^ ebp + 4 ^ ebp
- mov eax, [ebp+8] ; fetch argument from stack
- cmp eax, 0xA
- jge AthruF
- add eax, '0'
- jmp done
- AthruF:
- sub eax, 0xA
- add eax, 'A'
- done:
- leave
- ret ; return result in eax
- printShort:
- ; prelude
- push ebp
- mov ebp, esp
- sub esp, 8 ; make space for char ascii[] with word alignment
- mov [ebp-8], byte '\n'; ascii[4] = '\n'
- ; stack: [ arg | return address | saved ebp | 3 padding bytes | ascii[] ]
- ; ^ ebp
- mov edx, [ebp+8] ; load argument into edx
- and edx, 0x0f ; data & 0x0F
- push edx
- call hex2ascii
- pop edx
- mov [ebp-7], byte eax ; ascii[3] = hex2ascii(data & 0x0f)
- shr edx, 4 ; data >>= 4
- exit:
- mov eax, 1
- int 80h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement