Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- or : Alex Lazellari.
- # Creation Date : 31/10/2018
- # Description : A program that calculate the greatest common divisor.
- #
- # Registers used:v0,a0,t0,t1,t2,t3,zero.
- #v0 : From expression evaluation and function results.
- #a0 : Four parameters for subroutine.
- #t0 : Contains the value of the first integer of the user.
- #t1 : Contains the value of the second integer of the user.
- #t2 : Contains the result of the t1 mod t2.
- #t3 : Contains user's guest ,about the G.C.D..
- #zero : zero register is used in conditions.
- #
- .data
- message0 : .asciiz "Welcome USER, this program calculates the greatest common divisor of two integers and challenge you to find it. \nLet's start..!\n"
- message1 : .asciiz "Enter the first integer : "
- message2 : .asciiz "Enter the second integer : "
- #complex message--------------------
- message3 : .asciiz "\nWho is the greatest common divisor between "
- message4 : .asciiz " and "
- message5 : .asciiz " ?\nEnter value : "
- #-----------------------------------
- message6 : .asciiz "\nWrong! Try again."
- message7 : .asciiz "Who is the greatest common divisor ?\nEnter value : "
- message8 : .asciiz "\nExcellent you have found the right answer!."
- .text
- .globl __start
- __start:
- #Here the program prints the messge0.
- li $v0,4
- la $a0,message0
- syscall
- #print (“ Give an integer: ”);
- li $v0,4
- la $a0,message1 #The program prints the message1.
- syscall
- #a = Read_Integer();
- li $v0,5 #The program read the first integer.
- syscall
- move $t0,$v0
- #print (“ Give an integer: ”);
- li $v0,4
- la $a0,message2 #The program prints the message2.
- syscall
- #b = Read_Integer();
- li $v0,5 #The program read the second integer.
- syscall
- move $t1,$v0
- #complex message.
- #print (“ Who is the GCD of “+ a + “ and “ + b + “? ”);
- li $v0,4
- la $a0,message3
- syscall #The program prints the message3.
- li $v0,1
- move $a0,$t0
- syscall #The program prints the a variable.
- li $v0,4
- la $a0,message4
- syscall #The program prints the message4.
- li $v0,1
- move $a0,$t1
- syscall #The program prints the b variable.
- li $v0,4
- la $a0,message5
- syscall #The program prints the message 5.
- #---------------------------------------
- #Here the program calculate the G.C.D.
- #y = a % b;
- rem $t2,$t0,$t1
- #while (y!=0){
- # a=b;
- # b=y;
- # y=a%b;
- #}
- calculation:
- beq $t2,$zero,exit #The condition. If true then exit else
- move $t0,$t1 #the value of t1 goes to t0,
- move $t1,$t2 #value of t2 goes to t1
- rem $t2,$t0,$t1 #and result of t0 mod t1 is the value of
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement