Final
This commit is contained in:
17
numadd.asm
Normal file
17
numadd.asm
Normal file
@@ -0,0 +1,17 @@
|
||||
// Add from 1 to 50
|
||||
// R1 stores the result
|
||||
// R2 is a counter
|
||||
// By default, R1, R2 is 0
|
||||
// If R2 is 50, the program ends
|
||||
// If R2 is not 50, the program adds R2 to R1 and increments R2 by 1
|
||||
|
||||
lu12i.w $r1, 0x00000 // r1 = 0x00000000 (result)
|
||||
lu12i.w $r2, 0x00000 // r2 = 0x00000000 (counter)
|
||||
lu12i.w $r3, 0x00000
|
||||
addi.w $r3, $r3, 0x032 // r3 = 0x00000032 (50 in decimal)
|
||||
addi.w $r2, $r2, 1 // r2 = r2 + 1 (increment counter)
|
||||
add.w $r1, $r1, $r2 // r1 = r1 + r2 (add counter to result)
|
||||
beq $r3, $r2, 12 // If r2 = 50, branch to 'end' label
|
||||
b -12 // Jump back to the beginning of the loop
|
||||
// 'end:' label is here
|
||||
b -4 // Infinite loop: jump to itself
|
||||
Reference in New Issue
Block a user