Skip to content

Instantly share code, notes, and snippets.

@comtom
Created November 4, 2014 17:49
Show Gist options
  • Select an option

  • Save comtom/9c9279772820f171c611 to your computer and use it in GitHub Desktop.

Select an option

Save comtom/9c9279772820f171c611 to your computer and use it in GitHub Desktop.
example call a routine and show the result
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov ecx,'4'
sub ecx, '0'
mov edx, '5'
sub edx, '0'
call sum ;call sum procedure
mov [res], eax
; show display message
mov ecx, msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
; show sum result number
mov ecx, res
mov edx, 1
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
; show return in console
mov ecx, msg2
mov edx, len2
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
sum:
mov eax, ecx
add eax, edx
add eax, '0'
ret
section .data
msg db "The sum is:", 0xA,0xD
len equ $- msg
msg2 db "", 0xA,0xD
len2 equ $- msg2
segment .bss
res resb 1
@comtom

comtom commented Nov 4, 2014

Copy link
Copy Markdown
Author

$ ./demo
The sum is:
9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment