Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .text
- global _start
- _start:
- pop eax ; pop number of argc (diabaikan)
- pop eax ; pop argv[0] (diabaikan karena berisi nama program)
- pop eax ; pop argv[1] (ini dipakai untuk stringtoint)
- call stringtoint ; ECX berisi argumen bertipe integer sebagai counter
- _print:
- push ecx ; selamatkan counter di stack karena ECX dipakai juga di _print_hello
- call _print_hello ; print hello world
- pop ecx ; ambil lagi counter dari stack karena akan dipakai untuk looping
- loop _print ; kurangi ECX dengan 1, bila belum 0 kembali ke _print
- ; ini system call exit(0)
- mov ebx,0
- mov eax,1
- int 0x80
- _print_hello: ; systemcall write(1,msg,len)
- mov edx,len
- mov ecx,msg
- mov ebx,1
- mov eax,4
- int 0x80
- ret
- stringtoint: ; mengubah string di lokasi yang ditunjuk EAX menjadi integer di ECX
- ; EAX address of string
- xor ecx,ecx ; clear ECX
- xor ebx,ebx ; clear EBX
- mov bl,[eax] ; BL berisi kode ASCII string di lokasi yang ditunjuk EAX
- sub bl, 0x30 ; Kode ascii angka adalah 30h-39h, dikurangkan dengan 30h
- add ecx,ebx ; ECX ditambah EBX, ECX berisi nilai integer
- ret
- section .data
- msg db "Hello, World!",0xa
- len equ $ - msg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement