Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text:
  2.   global _start
  3.              
  4. _start:
  5. hex2ascii:
  6.   ; prelude
  7.   push    ebp                
  8.   mov     ebp, esp            
  9.  
  10.   ; stack: [ arg | return address | saved ebp ]
  11.   ;           ^ ebp + 8  ^ ebp + 4    ^ ebp
  12.   mov     eax, [ebp+8]    ; fetch argument from stack
  13.   cmp     eax, 0xA
  14.   jge     AthruF
  15.   add     eax, '0'
  16.   jmp     done
  17. AthruF:
  18.   sub     eax, 0xA
  19.   add     eax, 'A'    
  20. done:
  21.   leave
  22.   ret                     ; return result in eax
  23.  
  24. printShort:
  25.   ; prelude
  26.   push  ebp
  27.   mov   ebp, esp
  28.  
  29.   sub   esp, 8            ; make space for char ascii[] with word alignment
  30.   mov   [ebp-8], byte '\n'; ascii[4] = '\n'
  31.  
  32.   ; stack: [ arg | return address | saved ebp | 3 padding bytes | ascii[] ]
  33.   ;                                   ^ ebp
  34.   mov   edx, [ebp+8]      ; load argument into edx
  35.   and   edx, 0x0f         ; data & 0x0F
  36.   push  edx              
  37.   call  hex2ascii
  38.   pop   edx
  39.   mov   [ebp-7], byte eax ; ascii[3] = hex2ascii(data & 0x0f)
  40.   shr   edx, 4            ; data >>= 4  
  41.  
  42.  
  43.  
  44.  
  45. exit:
  46.   mov     eax, 1
  47.   int     80h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement