In hexidecimal notation, it would be 0x0251A024
In binary notation, it would be 00000010010100011010000000100100
Or, going the other direction, to a more sophisticated language, the green italicized part of the assembly code would be the following in pseudocode, which is much closer to languages like c++ or java:
int mult (int a, int b){
if (a == 0 || b == 0){
return 0;
}else if (a[0] == '0'){
return (mult (a<<1,>>1);
}else {
return (a + mult(a<<1,>>1);
}
}
And here is the actual assembly code:
[The weird lines across the page are a result of me using an easy way to indent lines in html...it is really kind of a pain to do it right, and evidently this website makes lines when I use that method]
#Lab 6
#Jonathan Gerrans
#Data Memory Section
.data
enterint: .asciiz "Please enter two integers: "
ans: .asciiz "The answer is: "
error: .asciiz "Error! Overflow!"
.align 2
#Program Memory Section
.text
.globl main
main:
li $v0, 4
la a0, enterint
syscall
li $v0, 5 #read in values
syscall
li $v1, 5
syscall
addi $s0, $zero, 0x00000001 #mask
addi $s1, $zero, 0x80000000 #mask2
move $s2, $v0
move $s3, $v1
move $s6, $zero
addi $s7, $zero, 0x00000020
overflow1:
addi $s6, $s6, 0x00000001 #overflow check
and $s4, $s2, $s1
sll $s2, $s2, 1
beq $s4, $zero, overflow1
overflow2;
addi $s6, $s6, 0x00000001 #overflow part two
and $s5, $s3, #s1
sll $s3, $s3, 1
beq $s5, $zero, overflow2
bgt $s6, $s7, error #print overflow error
add $a0, $zero, $v0 #first value
add $a1, $zero, $v1 #second value
jal mult
j end
mult:
beq $a0, $zero, return #if $a0 is zero, then return .
beq $a1, $zero, return #if $a1 is zero, then return .
and $t0, $a1, $v0 #check if first bit is a zero
bne $t0, $zero, notzero
sll $a0, $a0, 1 #shift a0 left one
srl $a1, $a1, 1 #shift a1 right one
jal mult #recurse
j return
notzero:
add $v0, $v0, $a0
sll $a0, $a0, 1 #shift a0 left one
srl $a1, $a1, 1 #shift a1 right one
jal mult #recurse
return: jr $ra
error:
li $v0, 4
la $a0, error
syscall
li $v0, 11 # ENDLINE
li $a0, 10
syscall
j main
end:
li $v0, 4 #Print the result
la $a0, ans
syscall
li $v0, 1
lw $a0, $v0
syscall
li $v0, 11 # ENDLINE
li $a0, 10
syscall
j main
This is so much fun!