a6-2004-37957-pseudo-instructions

pdf

School

University of Regina *

*We aren’t endorsed by this school

Course

201

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

pdf

Pages

8

Uploaded by DrBook9814

Report
Studocu is not sponsored or endorsed by any college or university A6 2004 37957 - pseudo-instructions Introduction to Digital Systems (University of Regina) Studocu is not sponsored or endorsed by any college or university A6 2004 37957 - pseudo-instructions Introduction to Digital Systems (University of Regina) Downloaded by black pearl (bp6735254@gmail.com) lOMoARcPSD|21438098
NAME: KHUSHIBEN PIYUSHBHAI PATEL STUDENT ID: 200437957 ASSIGNMENT NO: A6 Task 1 The following are some additional pseudo-instructions that one could define in the assembly system that we have discussed. For each of them, give one or more real assembly instructions to perform the expected operation. Remember: pseudo-instructions cannot modify any registers except the specified $rd and $pc for branch/jump (where applicable), but pseudo instructions may rely on $at for intermediate results. Provide short description of the potential use of each listed pseudo-instruction below. Answer: A). xchg $rt, o[$rs] #swap the memory in M[$rs+o] with $rt .xchg : use to changes data between to operands. $rt : A second type register in R-type instruction $rs : used first source register MIPS assembly instruction: Sub $at, $rt, $0 lw $rt, 0 [$rs] sw $at, 0 [$rs] B). slld $rs,$rt,shamt #Shift the double word rs:rt left by shamt Slld : used for shift left register $rt: A second type register in R-type of instruction $rs: is source register and used for first source register Shamt : it is used to shift two operands. MIPS assembly Instruction: Slr $at,rt, 32-shamt Sll $rs,rs, shamt Downloaded by black pearl (bp6735254@gmail.com) lOMoARcPSD|21438098
Sll $rs,$rs,$at C). double $rd, $rs #$rd = 2x($rs) Double: store data in 8 memory location $rt: A second type of register in R-type of instruction $rs : is first source register and used for first source register Li: li means load the immediate value, immediate values are 16-bits. Bgt: bgt means branching pseudo instruction Blt: blt means branching pseudo instruction Sll : sll means shift left register MIPS assembly instruction: li $at, 0x3FFF bgt $rs, $at, ERRORHANDLER li $at, 0xC000 blt $rs,$at, ERRORHANDLER sll $rd,$rs,1 D). triple $rd, $rs #$rd = 3x($rs) triple: store data in 12 memory locations $rt: A second type of register in R-type of instruction Li: li means load the immediate value, immediate values are 16-bits Bgt : bgt means branching pseudo instruction Blt: blt means branching pseudo instruction Sll : sll means shift left register Add: add $rs and 1, and stored the result in $rd MIPS assembly instruction: Li $at, 03xFFF Bgt $rs,$at, ERRORHANDLER Downloaded by black pearl (bp6735254@gmail.com) lOMoARcPSD|21438098
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Li $at, 0xC000 Blt $rs, $at, ERRORHANDLER SLL $at,$rs,1 Add $rd,$rs,1 E). mulacc $rd, $rs, $rt #$rd = ($rd)+($rs)x($rt) $rs:is first source register and used for first source register $rt: A second type of instruction $rd: destination register MIPS assembly instruction: mul $rs,$rt mflo $at add $rd,$rd,$at Task 2 Write a MIPS program to demonstrate the operation of the following switch statement: switch (S) { case 5: A = A + 1; break; case 25: A = A - 1; break; default: A = A * 2; break; } Implement and simulate your solution. Allocate .data locations for the variables S and A, and load these values into registers before performing the switch statement on the registers. Run your program several times with different values for these variables, to ensure that your program works as expected. Make sure that your program prompts the user for the values of S and A and displays results of the computation to the user. Answer: 1. Source code in a readable, well-formatted (tabulated, commented) way .text .globl __start __start: # execution starts here #print string li $v0,4 la $a0,inputS Downloaded by black pearl (bp6735254@gmail.com) lOMoARcPSD|21438098
syscall #read int and save to S li $v0,5 syscall sw $v0,S #print string li $v0,4 la $a0,inputA syscall #read int and save to A li $v0,5 syscall sw $v0,A lw $t1,S lw $t2,A switch: beq $t1,5,case5 beq $t1,25,case25 beq $t1,50,default case5: add $t2,$t2,1 b end_switch case25: sub $t2,$t2,1 b end_switch default: mul $t2,$t2,2 Downloaded by black pearl (bp6735254@gmail.com) lOMoARcPSD|21438098
b end_switch end_switch: sw $t2,A #display value of A li $v0,4 la $a0,ans1 syscall move $a0,$t2 li$v0,1 syscall la $a0,endl # syscall to print out li $v0,4 # a new line syscall #exit li $v0,10 syscall .data S: .word 0 A: .word 0 inputS: .asciiz "Enter values of S:" inputA: .asciiz "Enter values of A:" ans1: .asciiz "Now the value of A=" endl: .asciiz "\n" ## Screenshot of PC SPIM showing the emulator with your code successfully loaded Downloaded by black pearl (bp6735254@gmail.com) lOMoARcPSD|21438098
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Screenshots of PC SPIM console displaying the results of running your program with the following test inputs: 1. S = 5 ; A = 1 2. S = 25; A = 2 Downloaded by black pearl (bp6735254@gmail.com) lOMoARcPSD|21438098
3. S = 50; A = 3 Downloaded by black pearl (bp6735254@gmail.com) lOMoARcPSD|21438098