-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1.s
More file actions
33 lines (27 loc) · 970 Bytes
/
Copy pathlab1.s
File metadata and controls
33 lines (27 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
.data
space: .space 4
.text
main:
#read the integer
li $v0, 5
syscall
#use an address to store the input number
la $t1, space #t1 is the address used to store the number
move $t0, $v0
sw $t0, 0($t1) #save the input to address t1
#locate each byte of integer and swap their position
#change the location of 1st and 4th byte
lb $t3, 0($t1) #t3 is the binary representation of int byte 0
lb $t4, 3($t1) #t4 is the binary representation of int byte 3
sb $t3, 3($t1) #shift the binary representation of first byte into last byte
sb $t4, 0($t1)
#change the location of 4th byte
lb $t3, 1($t1) #t3 is the binary representation of int byte 1
lb $t4, 2($t1) #t4 is the binary representation of int byte 2
sb $t3, 2($t1) #shift the binary representation of first byte into last byte
sb $t4, 1($t1)
#print the converted integer
li $v0, 1 #system call code to print the integer
lw $a0, 0($t1) #load the sorted int
syscall
jr $ra