Created
November 4, 2014 17:49
-
-
Save comtom/9c9279772820f171c611 to your computer and use it in GitHub Desktop.
example call a routine and show the result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ./demo
The sum is:
9