Advertisement
Guest User

Untitled

a guest
Dec 21st, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. or : Alex Lazellari.
  2. # Creation Date : 31/10/2018
  3. # Description : A program that calculate the greatest common divisor.
  4. #
  5. # Registers used:v0,a0,t0,t1,t2,t3,zero.
  6. #v0 : From expression evaluation and function results.
  7. #a0 : Four parameters for subroutine.
  8. #t0 : Contains the value of the first integer of the user.
  9. #t1 : Contains the value of the second integer of the user.
  10. #t2 : Contains the result of the t1 mod t2.
  11. #t3 : Contains user's guest ,about the G.C.D..
  12. #zero : zero register is used in conditions.
  13. #
  14. .data
  15.     message0 : .asciiz "Welcome USER, this program calculates the greatest common divisor of two integers and challenge you to find it. \nLet's start..!\n"
  16.     message1 : .asciiz "Enter the first integer : "
  17.     message2 : .asciiz "Enter the second integer : "
  18.     #complex message--------------------
  19.     message3 : .asciiz "\nWho is the greatest common divisor between "
  20.     message4 : .asciiz " and "
  21.     message5 : .asciiz " ?\nEnter value : "
  22.     #-----------------------------------
  23.     message6 : .asciiz "\nWrong! Try again."
  24.     message7 : .asciiz "Who is the greatest common divisor ?\nEnter value : "
  25.     message8 : .asciiz "\nExcellent you have found the right answer!."
  26. .text
  27. .globl __start
  28. __start:
  29.     #Here the program prints the messge0.
  30.     li $v0,4
  31.     la $a0,message0
  32.     syscall
  33.     #print (“ Give an integer: ”);
  34.     li $v0,4
  35.     la $a0,message1     #The program prints the message1.
  36.     syscall
  37.     #a = Read_Integer();
  38.     li $v0,5            #The program read the first integer.
  39.     syscall
  40.     move $t0,$v0
  41.     #print (“ Give an integer: ”);
  42.     li $v0,4
  43.     la $a0,message2     #The program prints the message2.
  44.     syscall
  45.     #b = Read_Integer();
  46.     li $v0,5            #The program read the second integer.
  47.     syscall    
  48.     move $t1,$v0
  49.     #complex message.
  50.     #print (“ Who is the GCD of “+ a + “ and “ + b + “? ”);
  51.     li $v0,4
  52.     la $a0,message3    
  53.     syscall             #The program prints the message3.
  54.     li $v0,1
  55.     move $a0,$t0       
  56.     syscall             #The program prints the a variable.
  57.     li $v0,4
  58.     la $a0,message4
  59.     syscall             #The program prints the message4.
  60.     li $v0,1
  61.     move $a0,$t1
  62.     syscall             #The program prints the b variable.
  63.     li $v0,4
  64.     la $a0,message5
  65.     syscall             #The program prints the message 5.
  66.     #---------------------------------------
  67. #Here the program calculate the G.C.D.
  68.     #y = a % b;
  69.     rem $t2,$t0,$t1
  70.     #while (y!=0){
  71.     #   a=b;
  72.     #   b=y;
  73.     #   y=a%b;
  74.     #}
  75. calculation:
  76.     beq  $t2,$zero,exit     #The condition. If true then exit else
  77.     move $t0,$t1            #the value of t1 goes to t0,
  78.     move $t1,$t2            #value of t2 goes to t1
  79.     rem  $t2,$t0,$t1        #and result of t0 mod t1 is the value of
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement