Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .text:
- global _start
- _start:
- ;;; main() { }
- hex2ascii:
- ; stack: [ arg | return address | saved ebp ]
- ; ^ ebp + 8 ^ ebp + 4 ^ ebp
- mov eax, [ebp+8] ; fetch argument from stack
- and eax, 0x0F
- cmp eax, 0xA
- jge AthruF
- add eax, '0'
- jmp done
- AthruF:
- sub eax, 0xA
- add eax, 'A'
- done:
- ret ; return result in eax
- printShort:
- ; prelude
- push ebp
- mov ebp, esp
- sub esp, 8 ; make space for char ascii[] with word alignment
- mov esi, ebp ; set string address
- sub esi, 8 ; esi = ebp - 8
- mov [esi+4], 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 ; push for call
- call hex2ascii ; eax = hex2ascii(data & 0x0f)
- pop edx ; clean up stack
- mov [esi+3], al ; ascii[3] = (byte) eax
- shr edx, 4 ; data >>= 4
- and edx, 0x0F ; data & 0x0F
- push edx ; push for call
- call hex2ascii ; eax = hex2ascii(data & 0x0f)
- pop edx ; clean up stack
- mov [esi+2], al ; ascii[2] = (byte) eax
- shr edx, 4 ; data >>= 4
- and edx, 0x0F ; data & 0x0F
- push edx ; push for call
- call hex2ascii ; eax = hex2ascii(data & 0x0f)
- pop edx ; clean up stack
- mov [esi+1], al ; ascii[1] = (byte) eax
- shr edx, 4 ; data >>= 4
- and edx, 0x0F ; data & 0x0F
- push edx ; push for call
- call hex2ascii ; eax = hex2ascii(data & 0x0f)
- pop edx ; clean up stack
- mov [esi], al ; ascii[0] = (byte) eax
- mov eax, 4 ; syscall - write()
- mov ebx, 1 ; set stdout
- mov ecx, esi ; set string address
- mov edx, 5 ; print 5 bytes
- int 0x80
- leave
- ret
- exit:
- mov eax, 1
- int 0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement