Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help!!! Newbie can't even add 2 and 2

Status
Not open for further replies.

greadey

Technical User
Oct 25, 2001
231
0
0
GB
Hi all,

I am very new to assembly and have now got bored of "Hello World". I am trying to write my own program to simply add two numbers together and display the result. I have written the following program for nasm on Linux;

bits 32

section .data

num1 db 4
num2 db 5
bytes equ $-num2

section .text
global _start
mov ecx, num1 ; first number in ecx
add ecx, num2 ; add num2 to num1
mov eax, 4 ; system call to write()
mov ebx, 1 ; write to STDOUT
mov edx, bytes ; length of num2
int 0x80 ; call kernel

; Return to system from program
mov eax, 1
mov ebx, 0
int 0x80

The above program compiles and links with no problems at all and when I run the resulting executable I just get no output.

If someone would point out to me the error of my ways I would be very grateful.

thanks, greadey
 
I think that I know what your problem might be. It looks like you are adding the numbers, and storing them, instead of printing them. Have you tried a memory dump to check this? I ahven't worked with nasm, only masm, so I don't know how you'd do this, but it's something to check. If that's the problem, just stick an output subroutine in thee to print to the screen.
 
I dont know much about linux, so this post my be completely way of target, but...

before you call the interrupt to "write()",

I would expect to see you convert the results into a string.

I would expect to see the pointing registers that the call requires to find the string point to the source memory location of the string.

you need to what and how the function uses its parsed parameters and how to setup the operands it requres.
The people who have nothing to say and say it too loud have little knowledge, It's the quiet ones you need to worry about!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top