Thread: Code...
View Single Post
Old 11-12-2005, 02:18 PM   #10 (permalink)
tgo
Registered User
 
Join Date: Jul 2005
Posts: 185
OS: slackware 10.1


Send a message via AIM to tgo
Here is some linux assembly that takes in two numbers and gives you the output. Not very cool but was playing with C functions in assembly.

Useage:
Code:
tgo@localhost:~/asm$ nasm -f elf add.asm
tgo@localhost:~/asm$ gcc -o add add.o
tgo@localhost:~/asm$ ./add
Enter two numbers
25
30
Total of 25 and 30 is 55
tgo@localhost:~/asm$
Code:

Code:
[SECTION .text]

extern printf
extern scanf

global main

main:

	; show input banner

	push dword entermsg
	call printf
	add esp,4
	
	; get first number with scanf
	
	push dword one
	push dword num
	call scanf
	add esp,8
	
	; get second number with scanf

	push dword two
	push dword num
	call scanf
	add esp,8
	
	; add numbers and store in eax
	
	mov eax,[one]
	add eax,[two]
		
	; show total push values for totalmsg to display
	
	push eax 
	push dword [two]
	push dword [one]
	push totalmsg
	call printf
	add esp,16
	

[SECTION .bss]

one resd 1
two resd 1

[SECTION .data]

entermsg db 'Enter two numbers',10,0
totalmsg db 'Total of %d and %d is %d',10,0
num db '%d',0
__________________
My new homepage:
tgo is offline   Reply With Quote