Sign in to follow this  

[assembly] storing bytes to an array

Recommended Posts

I am making a program in assembly that reads a string of characters from the user and inserts it to a buffer of bytes. Then, the program has to search the buffer and copy some of the elements in a new array of bytes, depending on something that does not matter here.

The buffers are defined here:
.data # data segment
#.align 0

buffer: .byte 100 # stores input from the user
converted: .byte 100[/code]

The pseduocode for the loop is:
[code]while he haven't reached the NULL character
if condition is true
store data in new buffer (converted)

Data is loaded to register $t3.
[code]lb $t3, buffer($t0) # t0 is the counter that iterates through the 1st string ("buffer")
if condition is true
sb $t3, buffer($t1) ### PROGRAMS CRASHES HERE
increment $t1 by one # t1 shows the end of the second buffer
end if
increment $t0 by one

The program crashes at the commented line above.[i] I am sure that there is the problem because when it's commented out the program runs.[/i]
What is the problem? Am I using "sb" in a wrong way?

Thanks in advance for your help.

Share this post

Link to post
Share on other sites
I don't know anything about MIPS assembly programming, but here's what I would do: Write a tiny C function that does the same thing and compile it to assembly (option -S in gcc). You can then rewrite the function in your own style, but you can probably learn a lot from looking at a working example.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this