•
•
•
•
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
![]() |
•
•
Join Date: Dec 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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:
In case my description of the problem doesn't make sense, my terminal window looks like the following:
This is on a Solaris 10 box. Any idea what I'm doing wrong?
Thanks in advance!
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!
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 ?
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 ?
•
•
Join Date: Dec 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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.
This prints something like:
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.
.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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Assembly Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Assembly Forum
- Previous Thread: help me,its urgent, PC Alarm clock ASM code
- Next Thread: Two dimensional Arrays in MIPS



Linear Mode