p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Assembly Language (http://p2p.wrox.com/forumdisplay.php?f=161)
-   -   Integer I/O in assembly (http://p2p.wrox.com/showthread.php?t=53300)

kaycg January 28th, 2007 12:21 PM

Integer I/O in assembly
 
This might sound like a stupid question but is there a way to output integer values just using assembly and linux system calls without having to use the printf command and by extension the c library functions.

This is part of a project at university and we would like to have assembly that performs calculations and gets a 32 bit integer result and then output that result to standard output. The project group would prefer to do it without having to link it with the c libraries.

If this can be done I'd appreciate it, some help on how to do it. If it can't be done I'd appreciate being told that too, and I'll just use printf.

Thanks in advance


lewkor May 10th, 2007 05:15 PM

First make sure that you can write a byte to stdio. Put 65 in a register and print it. You should see a 'A' on the screen.

What you need to do is divide the number by the radix (presumably 10) and save the remainder and the quotient. save the remainder on a stack. Divide the new quotient by the radix - save the new remainder. Repeat until the quotient is 0.

What you have now is numbers between 0 and 9 saved in a stack. For each element on the stack add 0x30 (ascii 0) to that value and print it. The stack is conveniently contained in the call stack if you make this a recursive function.;)

When you have that mastered then you can try to create a function that will print float/doubles.

Have fun!


kaycg May 11th, 2007 05:00 AM

Thanks lewkor.

Unfortunately the projects finnished now. We went with the C-library functions option. We got great marks on the project though for anyone interested (probably no-one).

I'll definatley look into this though, while to late for the project, great to know for the rest of my life in programming

Thanks once again



All times are GMT -4. The time now is 02:39 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.