.data prompt: .asciiz "enter a number: " .globl main .text main: li $t1, 10 li $t2, 5 li $t3, 2 li $v0, 4 la $a0, prompt syscall li $v0, 5 syscall move $t0, $v0 bgtz $t0, one add $t3, $t1, $t2 one: addi $t2, $t2, -2 mult $t0, $t3 mflo $t4
.data prompt: .asciiz "enter a number: " .globl main .text main: li $t2, 5 li $t3, 4 addi $t4, $zero, 3 li $v0, 4 la $a0, prompt syscall li $v0, 5 syscall move $t0, $v0 li $v0, 4 syscall li $v0, 5 syscall move $t1, $v0 blt $t0, $t1, one add $t5, $t1, $t2 b two one: add $t5, $t0, $t2 two: mult $t3, $t5 mflo $t6 div $t6, $t4 mfhi $t2 mflo $t3
li $t0, 2 li $t1, 15 addi $t2, $zero, 0 top: bgt $t0, $t1, end add $t2, $t2, $t0 addi $t0, $t0, 2 b top end:
.data prompt: .asciiz "enter a number: " .globl main .text main: li $t0, 1 li $t1, 3 li $t3, 1 move $t4, $zero li $v0, 4 one: bgt $t0, $t1, six move $t5, $zero li $v0, 4 la $a0, prompt syscall li $v0, 5 syscall move $s0, $v0 addi $t2, $zero, 0 two: bgt $t2, $t3, five li $v0, 4 la $a0, prompt syscall li $v0, 5 syscall move $s1, $v0 blt $s0, $s1, three add $t5, $t5, $s0 b four three: add $t5, $t5, $s1 four: addi $t2, $t2, 1 b two five: add $t4, $t4, $t5 addi $t0, $t0, 1 b one six:
Show the assembler instructions equivalent to each of the following. Be sure to show where each numbered block of code will be placed.
if $t1 != $t2 && $t2 > $t5 { . . (1) . } else { . . (2) . } . . (3) .
if ($t1 <= $t2 || $t3 > $t4) { . . (1) . } else { . . (2) . } . . (3) .
if $t1 > $t2 + $t3 { . . (1) . } else if $t3 + $t1 == $t4 { . . (2) . } else { . . (3) . } . . (4) .
if $t1 <= $t2 { . . (1) . if $t3 != 0 { . . (2) . } else { . . (3) . } } else { . . (4) . } . . (5) .
if $t1 >= $t2 { if $t0 < $t3 { . . (1) . } else { . . (2) . } . . (3) . } else { if $t0 != 10 { . . (4) . } } . . (5) .
if $t1 <= $t2 + 1 { . . (1) . } else { if $t1 > $t2 || $t1 == 0 { . . (2) . } else { . . (3) . } . . (4) . } . . (5) .
$t1 = 10 while $t1 != 0 { $t2 = $t2 + $t3 $t1 = $t1 - 1 }
$t3 = 0 for ($t1 = 0 ; $t1 < $t2 ; $t1++) { print prompt: "Enter a num: " read num $t2 = num * num print $t2 }
$t2 = 0 $t3 = 0 for ($t1 = 0 ; $t1 < 100 ; $t1++) { print prompt: "Enter a num: " read num if num is even $t2 = $t2 + num else t3 = $t3 + num } print "Sum of evens: " $t2 print "Sum of odds: " $t3
xton = 1 print prompt: "Enter a num: " read x while (x != 0) { print "Enter exponent: " read n for (i = 1 ; i <= n ; i++) { xton = xton * x } print "x^n = " print xton xton = 1 print prompt: "Enter a num: " read x }
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2020