Sunday, October 13, 2013
Assign 2 - Exercise 2.13 ASM
Link to source file
https://docs.google.com/file/d/0B3pg-UsmVkpFT2RGcUFVUkVYRVE/edit?usp=sharing
.data
space: .asciiz "\n" # Print New Line
.text
__start:
#2.13.1
#a
li $t0, 0xAAAAAAAA
li $t1, 0x12345678
sll $t2, $t0, 30
sll $t2, $t2, 14
or $t2, $t2, $t1
move $a0, $t2
jal printint
#b
li $t0, 0xF00DD00D
li $t1, 0x11111111
sll $t2, $t0, 30
sll $t2, $t2, 14
or $t2, $t2, $t1
move $a0, $t2
jal printint
#output
#305419896
#286331153
#2.13.2
#a
li $t0, 0xAAAAAAAA
li $t1, 0x12345678
sll $t2, $t0, 4
andi $t2, $t2, -1
move $a0, $t2
jal printint
#b
li $t0, 0xF00DD00D
li $t1, 0x11111111
sll $t2, $t0, 4
andi $t2, $t2, -1
move $a0, $t2
jal printint
#output
#-1431655776
#14483664
#2.13.3
#a
li $t0, 0xAAAAAAAA
li $t1, 0x12345678
srl $t2, $t0, 3 #shift right t0 by 3 store in t2
andi $t2, $t2, 0xFFEF #t2 += 0xFFEF
move $a0, $t2
jal printint
#b
li $t0, 0xF00DD00D
li $t1, 0x11111111
srl $t2, $t0, 3 #shift right t0 by 3 store in t2
andi $t2, $t2, 0xFFEF #t2 += 0xFFEF
move $a0, $t2
jal printint
#output
#21829
#47617
#2.13.4
li $t0, 0x0000A5A5
li $t1, 0x00005A5A
sll $t2, $t0, 1 #t2 = t0*2
andi $t2, $t2, -1 #t2 = t2 & -1
move $a0, $t2
jal printint
andi $t2, $t1, 0x00F0 #t2 = t1 & 0x00F0
srl $t2, $t2, 2 #t2 = t2 >> 2 # t2/4
move $a0, $t2
jal printint
#output
#84810
#20
#2.13.5
xor $t2, $t2, $t2 #clear register
li $t0, 0xA5A50000
li $t1, 0xA5A50000
sll $t2, $t0, 1 #t2 = t0*2
andi $t2, $t2,-1 #t2 = t2 & -1
move $a0, $t2
jal printint
andi $t2, $t1, 0x00F0 #t2 = t1 & 0x00F0
srl $t2, $t2, 2 #t2 = t2 >> 2 # t2/4
move $a0, $t2
jal printint
#output
#1263140864
#0
#2.13.6
xor $t2, $t2, $t2 #clear register
li $t0, 0xA5A5FFFF
li $t1, 0xA5A5FFFF
sll $t2, $t0, 1 #t2 = t0*2
andi $t2, $t2,-1 #t2 = t2 & -1
move $a0, $t2
jal printint
andi $t2, $t1, 0x00F0 #t2 = t1 & 0x00F0
srl $t2, $t2, 2 #t2 = t2 >> 2 # t2/4
move $a0, $t2
jal printint
#output
#1263271934
#60
j done
printint:
addi $v0, $zero, 1 # load appropriate system call code into register $v0;
# code for printing integer is 1
syscall # call operating system to perform operation
addi $v0, $zero, 4 # load appropriate system call code into register $v0;
# code for printing string is 4
la $a0, space # load address of the string
syscall
jr $ra
done:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment