Skip to content
Advertisement

How can I create a basic NASM Assembly (Linux) calculator to add two integers?

I had a go at it, and tried:

JavaScript

Sorry about all the XOR instructions, I just wanted to make sure registers were cleared before I used them for a system call, I’m still learning assembly and not sure about what instructions will render a register empty.

When I compile, link and run this I can enter the two integers only if I include the ENTER character, i.e. newline character. An integer can’t be added to it, so already that causes a problem. So when I enter both of them, I get no further output on the screen from the program, and the it just ends.

How can I correct it?

(Using C or C++ with ASM is not an option in this case.)

Advertisement

Answer

It’s not about “correcting” your code as it is about writing a missing part of it.

You have to parse integers, ignoring separating whitespace. Add them, then convert a result into a string. Then output this string. Calling scanf or strtol or printf is probably inacceptable to you, as it’s using a standard C library.

Advertisement