Results 1 to 7 of 7
So I've been toying with assembly, and I decided to take a break from my reading to try to make something completely on my own.
It returns the inverse of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-30-2011 #1Just Joined!
- Join Date
- Nov 2010
- Location
- Alaska
- Posts
- 55
Assembly (simple code issue)
So I've been toying with assembly, and I decided to take a break from my reading to try to make something completely on my own.
It returns the inverse of a number, except for some bizarre reason, when I tell it to print the string prompt, it prints prompt and result, then result again after the inverse is found.
Help anybody?
Oh yeah, I'm using Dr. Paul Carter's assembly tutorial, and I was supposed to download some include files. A quick google search can get you the site.
nasm -f elf inverse.asmCode:%include "inc/asm_io.inc" segment .data prompt db "What do you want to inverse? " outmsg db "The inverse of your number is " segment .bss input resd 1 segment .text global asm_main asm_main: enter 0,0 pusha mov eax,prompt ;; eax = "enter the number" call print_string ;; prints the value of eax call read_int ;; gets int from user and puts in eax mov ebx,eax not ebx ;; inverse command mov eax,outmsg ;; "inverse of number is" call print_string ;; ^^^^^^^^^^^^ mov eax,ebx call print_int ;; Prints the number call print_nl popa mov eax,0 leave ret
gcc -o inverse inverse.o inc/driver.c inc/asm_io.o
Processor 80x86Last edited by MisterDood; 06-30-2011 at 04:09 PM. Reason: Commented code
- 07-01-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,156
You don't show the code for the call targets, print_string, pinrt_int, etc.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 07-06-2011 #3Just Joined!
- Join Date
- Nov 2010
- Location
- Alaska
- Posts
- 55
Sorry for the late reply, I've been busy working lately.
Anyways, I thought that when I called print_string, it printed the value of eax by default. How would I go about adding another target to that? I'm still very new to this, so please forgive my lack of knowledge. Also, thank you.
P.S. I've realized lately that people who help others don't get enough credit these days, or maybe they never did really. Without help forums like these, Linux probably wouldn't have at least 90% of its current users.
- 07-06-2011 #4Just Joined!
- Join Date
- Nov 2009
- Location
- Sweden
- Posts
- 35
- 07-06-2011 #5Just Joined!
- Join Date
- Nov 2010
- Location
- Alaska
- Posts
- 55
That you very much kind sir. That's something my tutorial failed to mention (Or maybe something I failed to remember).
- 07-06-2011 #6Just Joined!
- Join Date
- Nov 2009
- Location
- Sweden
- Posts
- 35
I looked at the tutorial and it is explained on page 17.
One more thing:
Your comment doesn't make sense here. This instruction loads the address of the label "prompt" into eax, which is what you want in this case. If you want to load the data on that address, you should use mov eax,[prompt] instead.mov eax,prompt ;; eax = "enter the number"
Since eax is 32 bits long, this would only load the word "What" into eax, not the whole string. That's why print_string expects you to call it with the address of the string in eax.
- 07-07-2011 #7Just Joined!
- Join Date
- Nov 2010
- Location
- Alaska
- Posts
- 55
That makes a lot more sense. Thank you. I should go back and re-read the first chapter since my reading skills have obviously failed me. I also have a few questions about the use of anding (other than counting bits) and how the stack is used (though I know how the stack works thanks to MTG xD), but I'll ask those another time. In the mean time, I'll be re-reading this tutorial. Thank you all for your help and patience. Time to hit the books (or PDFs) before bed.
P.S. My inversing program works now that I terminated the strings ( bla , 0 ). Just thought I'd relieve everyone of the suspense.


Reply With Quote

