Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addi x2, x0, 1600 //initialize the stack to 1600, x2= stack pointer
- ecall x6, x0, 5 //read the input to x5
- add x10, x6, x0 //put the parameter in x10
- addi x2, x2, -8 //make room to store x5
- sd x6, 0(x2) // place x6 at the top
- jal x1, myswap
- ld x6, 0(x2) //restore x5 rom the stack
- addi x2, x2, 8 //pop the stack
- ecall x0, x10, 2 //print the value returned from the functions
- ecall x0, x6, 2 //print the original value
- # ORG 96 //stops infinite recurring
- beq x0, x0, exit # if $t0 == $t1 then target
- myswap:
- addi x2, x2, -8
- sd x8, 0(x2)
- addi x5, x0, 255 // x5 is a 0000 ..011111111
- and x6, x10, x5 // x6 is m=i&a, m has lest significant byte
- srai x7, x10, 8 //x7 is I shifted to left by 8
- and x7, x7, x5 //x7 is the second least sig. Byte of I
- srai x8, x10, 16 // shift I by 16 put it in x8
- slli x8, x8, 8
- or x8, x8, x6 //append the second least significant byte
- slli x8, x8, 8
- or x8, x8, x7
- add x10, x0, x8
- ld x8, 0(x2) // pop x8 frm the stack
- addi x2, x2, 8
- jalr x0, 0(x1)
- exit:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement