- Here is a binary number: 01000011
- Is it odd or even? odd
- You can't write it that way in a computer language. Write it as
a character, base-16 number, and decimal
number. 'C'
0x43
67
- Convert to signed decimal the number 0xFFFFFFE3
It is negative. 2's complement
0x1c+1 = 0x1d, so number is -39
- X, Y, and Z are numbers. Write an assembly language program to
print the result of (X + Y) / Z , and then a string labeled finish:
lw $t0, X
lw $t1, Y
lw $t2, Z
add $a0, $t0, $t1 #a0 = X+Y
div $a0, $a0, $t2 #a0 = (X+Y)/Z
li $v0, 1 # print int service
syscall # print result that's in $a0
la $a0, finish # print the final string
li $v0, 4
syscall
li $v0, 10 # exit program
syscall
- Write a function whose argument (in $a0) is the address of a
string. It should return (in $v0) the number of 'e's in the string.
count_es:
li $v0, 0 # v0 holds count of 'e's
celoop:
lb $t0, ($a0) # in string addressed by a0
beqz $t0, endce # end of string
bne $t0, 'e', not_e # if its an 'e'
add $v0, 1 # count it
not_e:
add $a0, 1 # point to next char
j celoop
endce:
jr $ra # return count in $v0
- Write a function whose arguments are the address of an array of
words, and the length of that array (in $a1). Return the maximum value
in the array.
max:
lw $v0, ($a0) #max = a[0] first array element
mloop:
sub $a1, 1 #count--
add $a0, 4 #a++ point to next word
blez $a1, mend # no more words
lw $t0, ($a0) # get next word
ble $t0, $v0, notgreater
move $v0, $t0 #found new max
notgreater:
j mloop # keep looking
mend:
jr $ra #return with max in $v0
- for this instruction, using the information on pp. 60-61, show
how it is encoded in binary, and hexadecimal.
sub $t3, $t1, $t2