User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,772 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 977 | Replies: 2
Reply
Join Date: Dec 2007
Posts: 2
Reputation: jegspam is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jegspam jegspam is offline Offline
Newbie Poster

Question User Input (scanf) in SPARC?

  #1  
Dec 1st, 2007
I'm attempting to revisit assembly after several years of not having used it at all, and I'm having a bit of trouble with simple I/O. My program is designed to read a number from the user and spit it right back out. The "%c" is simply to remove the newline character (enter) from the buffer. This seems simple enough, and I can get it to work with strings, but for some reason I get a "Bus Error" after I input a number.

My code is as follows:
.section ".data"
informat: .asciz "%d%c"
outformat: .asciz "The number was: %d\n"
input: .word
returnkey: .byte

.section ".text"
.global main
.align 4
main:

save %sp, -96, %sp

set informat, %o0
set input, %o1
set returnkey, %o2
call scanf
nop

set outformat, %o0
set input, %o1
call printf
nop

ret
restore

In case my description of the problem doesn't make sense, my terminal window looks like the following:
#> gcc test.s
#> ./a.out
5
Bus Error
#>

This is on a Solaris 10 box. Any idea what I'm doing wrong?

Thanks in advance!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: User Input (scanf) in SPARC?

  #2  
Dec 2nd, 2007
1. Write it in C
2. Compile with "gcc -S prog.c"
3. Inspect prog.s to find out how the compiler does it.
4. Figure out how you should have passed the ADDRESS of input and returnkey to the function.
5. Does .word really reserve the same space as an int in C ?
6. Do you need a .align 4 in front of your input declaration ?
Reply With Quote  
Join Date: Dec 2007
Posts: 2
Reputation: jegspam is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jegspam jegspam is offline Offline
Newbie Poster

Question Re: User Input (scanf) in SPARC?

  #3  
Dec 2nd, 2007
Thanks for your reply, Salem. I think I have scanf working correctly now, but printf looks like it is printing an address. It is my understanding that printf doesn't need to be passed the address.

.section ".text"
.global main
main:

save %sp, -96, %sp

set instr, %o0
set [data], %o1
set [enterkey], %o2
call scanf
nop

set outstr, %o0
set data, %o1
call printf
nop

ret
restore

.section ".data"
instr: .asciz "%d"
outstr: .asciz "The number was: %d"
.align 4
data: .word
enterkey: .byte

This prints something like:
The number was: 133332

Forgive me if this seems like an elementary problem - its been 4 years since I've looked at any assembly, and I didn't know it well then. The book I'm looking at has poor examples, so I'm trying to piece together what I can from the web.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Assembly Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Assembly Forum

All times are GMT -4. The time now is 9:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC