Simple mathmatics written in Assembly code using nasm
Hi I have had a go at a tutorial I got in a linux format magazine and I have found a similar tutorial on this site:
http://docs.cs.up.ac.za/programming/asm/derick_tut/ I'm haveing difficulty with adapting this to do something with numbers. In short all I want to do is make a simple assembly example (for teaching) that does the following: 1: takes two numbers input (optional as I'm guessing this is complex?) 2: adds them together 3: Displays the result I've had a go at it but without luck yet. Can anyone tell me if i'm making some stupid/simple mistake or give me a pointer to a website with a simple solution. So far all I have found (in 3.5 hours of googling) have been helo world tutorials, tutorials that look confusingly different from nasm and examples that are too complex for my level. And i found the nasm manual too technicxal for my relative beginner status Any help would be much apreciated. Here is my code: Code:
section .data |
ecx does not contain the output your looking for. ecx contains a 32 bit integer, 50 specifically, but write needs a pointer to an array of characters. You'll just get a segmentation fault. You need to convert that integer to a string first. The easiest way to do what your doing is to link w/ the C library. That way you can use itoa, or scanf and printf. Creating functions to convert an integer to a string and back in assembly is not difficult, but it is beyond the level your looking for. In my assembly class a while ago, our teacher just created an include file w/ macros to run the C functions for you. This worked well since it allowed the class to create non-trivial examples w/o worrying about I/O.
|
While this doesn't directly answer your question, if you're trying to learn assembler, I suggest starting with HLA (High Level Assembly). I've been spending a bit of my free time learning it, and it's nothing more than x86 assembly language with C-like syntax.
|
Thanks for the pointers. I figured that there was an issue with trying to output an integer as text. The rest looked like it was working.
I have also found (for others looking to learn assembly) a website with a forum for flat assembler (which is similar to nasm). This has some useful resources. Just in case someone has the same situation as me my recommendation is to get both the pdf and the example code file from this site: PC Assembly Tutorial That covers all the basics and more. An excellent tutorial. If it helps anyone then here is my code etc: Code:
%include "asm_io.inc" ;library with input/output routines Code:
gcc -c driver.c Hope this helps others... and not just to cheat on their homework (Which seems to be what most people asking many of the questions I have been googling are after). |
All times are GMT -5. The time now is 07:10 AM. |