Advertisement
Guest User

asm

a guest
Oct 5th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text
  2.  
  3. global _start
  4.  
  5. _start:
  6. pop eax ; pop number of argc (diabaikan)
  7. pop eax ; pop argv[0] (diabaikan karena berisi nama program)
  8. pop eax ; pop argv[1] (ini dipakai untuk stringtoint)
  9. call stringtoint ; ECX berisi argumen bertipe integer sebagai counter
  10.  
  11. _print:
  12. push ecx              ; selamatkan counter di stack karena ECX dipakai juga di _print_hello
  13. call _print_hello     ; print hello world
  14. pop ecx               ; ambil lagi counter dari stack karena akan dipakai untuk looping
  15. loop _print           ; kurangi ECX dengan 1, bila belum 0 kembali ke _print
  16.  
  17. ; ini system call exit(0)
  18. mov ebx,0
  19. mov eax,1
  20. int 0x80
  21.  
  22. _print_hello:   ; systemcall write(1,msg,len)
  23. mov edx,len
  24. mov ecx,msg
  25. mov ebx,1
  26. mov eax,4
  27. int 0x80
  28. ret
  29.  
  30. stringtoint: ; mengubah string di lokasi yang ditunjuk EAX menjadi integer di ECX
  31. ; EAX address of string
  32. xor ecx,ecx   ; clear ECX
  33. xor ebx,ebx   ; clear EBX
  34. mov bl,[eax]  ; BL berisi kode ASCII string di lokasi yang ditunjuk EAX
  35. sub bl, 0x30   ; Kode ascii angka adalah 30h-39h, dikurangkan dengan 30h
  36. add ecx,ebx   ; ECX ditambah EBX, ECX berisi nilai integer
  37. ret
  38.  
  39. section .data
  40. msg db "Hello, World!",0xa
  41. len equ $ - msg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement