×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

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.

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

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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close