cs104 Lab 2

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

PROGRAM TO ADD/SUB TWO INTEGERS

.data
num1:.asciiz "Enter the first number:"
num2: .asciiz "Enter the second number:"
result: .asciiz "The result is :"
.text
li $v0, 4 #command to print a string
la $a0, num1 #loading a string to print into the argument
syscall #execute the command
li $v0, 5 #command for reading an integer
syscall
move $t0,$v0
li $v0, 4 #command to print a string
la $a0, num2 #loading a string to print into the argument
syscall #execute the command
li $v0, 5 #command for reading an integer
syscall move $t1,$v0
add $t2,$t0,$t1 # t2=t0+t1
li $v0,4
la $a0,result
syscall
li $v0,1
la $a0, ($t2) syscall

IF ELSE STATEMENT

.data
msg1:.asciiz "The numbers are equal"
msg2:.asciiz "The numbers are not equal"
.text
li $t0,8
li $t1,8
beq $t0,$t1,numbersequal
bne $t0,$t1,numbersnotequal
numbersequal: li $v0,4
la $a0,msg1
syscall
numbersnotequal:
li $v0,4 la $a0,msg2 syscall

LOOPS USING MARS

.data

.text
li $t0,1 #t0=1, similar to i=1
li $t1,0 #t1=0, similar to sum=0

while:
beq $t0,11, exit #if i=11 then exit
add $t1,$t1,$t0 # t1=t1+t0, or similar to sum=sum+i
addi $t0,$t0,1 #t0=t0+1, or similar to i=i+1
j while
exit:
li $v0,1
move $a0, $t1
syscall

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy