Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Download pa04.asm in a directory. Copy your updated cs47_macro.asm from PA03 in the same directory. Add the following two macros in this cs47_macro.asm push($reg) :
- Download pa04.asm in a directory.
- Copy your updated cs47_macro.asm from PA03 in the same directory.
- Add the following two macros in this cs47_macro.asm
- push($reg) : Push data in register $reg into stack.For example push($s0) will push the content of register $s0 into the stack.
- pop($reg) : Pop from stack into register $reg. For example pop($t0) will pop content from stack and copy into register $t0.
- Assemble and execute pa05.asm. This should create following sample output
Pushing -> 16 | 12816 | 32 | 1985229328 Popping -> 1985229328 | 32 | 12816 | 16
This is using MIPS MARS program
File Edit Run Sellings Tools Help Run speed at max (no interaction) 1 Execute Copro 1 Cupruco Vam Number C547_macro.asm Value Szero Sve Sul Sal Saz Sa sta Stl St> st3 St4 St5 sta st3 1 l include "./cs47 nacro.asm. Z 3 data Ex10808800 4 var a: .byte 3x13 y Type: Ciar (8-bit) 5 var 5: .helt 3x3210 Type: Short (26-X 6 var 4: .byte 8x23 Type: Char (9-11) 7 var di word 3x 76543218 Type: int (32-bit) 8 9 push: .asci z "Pushing-> 99 pop: ascli2 "Papping - 10 char pipe: .ascitz"1" char ni asciiz "1" 12 13 .text 14 .globl main 15 0212 16 #these are all pseudo instruction 17 # HIPS natively supports only relative 18 address translation le.y. ib sse, 8x2345/59p)! 19 ID $56, var_a X Riso = var a'17: 20 IN $51, var_ Ris]) = var 1115:8) 21 ID $S2, var cy RS2) - var 17:21 22 IW $53, var d x Ris3) = /var d1115:8) 23 24 25 # PUS! the 50...4 to stack 26 print string push) 27 push(30) 28 print reg int($) 29 30 push($51) 31 print str(char papel 32 print l'egant (1) 33 34 push($s2) 35 print_str(char pipe! 36 print reg int($52) 37 38 push($s3) 39 print str(char pipe 10 print l'eg int($53) Ssa ss1 Ss2 553 SS4 1 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 18 19 20 21 22 23 14 24 25 26 27 28 29 30 31 0x80080000 x2000 8x38888888 0x80080080 GX2920 Ox30830830 0x80070080 GX8G186186 8x38888888 0x80080080 HAASAGMS Ox30030038 0x80080680 GxAGDAGDAG Ox30030030 0x0000000 HAAGMGRMS Ox30030030 0x80070080 GxAGDAGDAG Ox30030030 0x0000000 GxAGRAM Ox30030030 0x80080680 GxAGDAGDAG Ox30030030 0x8007000 Gx192282 Oxffferta 0x80080080 Gx0PAGDAG Ox30430030 Ox80030990 Gx2000 $55 S56 Ss7 sta St9 ska Ski Son SSP Sto Sra pc hi 10 Line: 1 Column: 1 Shuw Line Numbers Run I/O Clear File Edit Run Sellings Tools Help Run speed at max (no interaction) 1 Execute Copro 1 Cupruco Number C547_macro.asm Value Vans Szero #Push the 58...4 to stack print string gush) push($) print leg int($) Sve Svi 25 26 27 28 29 39 31 32 33 34 35 36 37 38 39 40 41 AZ 43 push() print_str(char pipe! print reg int($51) push($s2) print str(char pipe print reg int($s2) push($53) print_str(char pape! print reg int(53) Sal Saz Sa sta Sti St2 st3 St4 St.5 sta St7 Ssa ssl Ss2 553 S54 1 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 18 19 20 21 22 23 14 24 25 26 27 28 29 30 31 print strichar nl) 0x80080000 x2000 8x38888888 0x80080080 GX2920 Ox30830830 0x80070080 GX8G186186 8x38888888 0x80080080 HAASAGMS Ox30030038 0x80080680 GxAGDAGDAG Ox30030030 0x0000000 HAAGMGRMS Ox30030030 0x80070080 GxAGDAGDAG Ox30030030 0x0000000 GxAGRAM Ox30030030 0x80080680 GxAGDAGDAG Ox30030030 0x8007000 Gx192282 Oxffferta 0x80080080 Gx0PAGDAG Ox30430030 Ox80030990 Gx2000 $55 # pop the t8...4 lo steck print string pop) popiste print leg int($to) pop(st11 print_str(char pape} print leg int($ta) 15 46 47 48 49 50 51 52 53 54 55 56 57 58 59 69 61 popis:2 print str(char pipe print reg int($ta) popst3 print str(char pipe? print reg antists) print str(char nl) systent Exit exit Ss7 St8 St9 ska Ski Son SSD Sfo Sra pc ha 10 53 Line: 1 Column: 1 Shuw Line Numbers Run I/O File Edit Run Sellings Tools Help Run speed at max (no interaction) 1 Execute Copro 1 Cupruco Vam Number pa04.asm Value Szero --- Sve Sul 1 ---- MACRO DEFINITIONS z y Necro: print ser 3 y Usage: print stri address of the strings) acro print strisery 5 li sve, 4 x Systa call code for print str 6 la Sea, sargy Address of the string to print 7 syscall x Print the string 8 end macro Sal Saz Sa sta Stl St> st3 St4 St.5 sta st3 Ssa ssl Ss2 553 S54 1 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 18 19 20 21 22 23 14 24 25 26 27 28 29 30 31 0x80080000 x2000 8x38888888 0x80080080 GX2920 Ox30830830 0x80070080 GX8G186186 8x38888888 0x80080080 HAASAGMS Ox30030038 0x80080680 GxAGDAGDAG Ox30030030 0x0000000 HAAGMGRMS Ox30030030 0x80070080 GxAGDAGDAG Ox30030030 0x0000000 GX4Gpada Ox30030030 0x80080680 GxAGDAGDAG Ox30030030 0x8007000 Gx192282 Oxffferta 0x80080080 Gx0PAGDAG Ox30430530 0x80070080 Gx2000 19 Necroprin int 11 x Usage: print intisve!) 12 lacro print intisarg> 13 li Svo, 1 Systes cail code for printing 14 li se, argy Integer to print 15 syscall x Print the integer 16 end necro 17 18 X Necro : reedint 19 Usage: read Anve!) 29 Macro reed int(sreg) 21 li sva, 5 y Systa call for read in 22 Syscall 23 nave treg, $vo Integer to sove to new seory location 24 end macro 25 26 X Necro : reedint 27 Usage , read Anclave! of inputs) 28 Nacro print_reg int(sreg) 29 li sve, i Systen Cell for print reg int 30 nave $ab, Sreg w Integer to move to new lewory location 31 syscall # Print the reg in 32 enc necro 33 34 y NecroSep lo 35 Usage: Swap corsvar of inputs) 36 Nacro swap hila (Step, Steng2 37 nhi Stempi x Move froe ni register 38 nflo step2 X Move fra lo register 39 thi stenpz x Move Trov ni register 40 nt lo stempl x Move tro o register $55 Ss7 st S19 ska ski Son SSP Sfo Sra pc hi 10 Line: 1 Column: 1 Show line Numbers Run I/O File Edit Run Sellings Tools Help Run speed at max (no interaction) 1 Execute Copro 1 Cupruco a04 asm Number Value Vans Szero Li sve, 4 L 38, 35tra1f3 Syscall # This can be simplified, by calling print strisstrowe! Print the cow string, Sve Svi 57 58 59 60 61 SZ 53 li Sva, 4 l b, strL syscall # This can be simplified, by calling print strisstro! y Print the lo value 55 56 67 Li sve, 4 la sao, sstrEquel syscall # This can be simplified, by calling print strisstrEqual! Y Print the equel string '=' Sal Saz Sa sta Sti St2 st3 St4 St.5 sta nflo sti printreg int sti) end macro y Print Cie reg int sti Vacro lwa (sreg, sui, SLL) Lui $res. $ui ori reg. reg. $14 .end Macro Ssa ssl Ss2 553 S54 1 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 18 19 20 21 22 23 14 24 25 26 27 28 29 30 31 0x80080000 x2000 8x38888888 0x80080080 GX2920 Ox30830830 0x80070080 GX8G186186 8x38888888 0x80080080 HAASAGMS Ox30030038 0x80080680 GxAGDAGDAG Ox30030030 0x0000000 HAAGMGRMS Ox30030030 0x80070080 GxAGDAGDAG Ox30030030 0x0000000 GX4Gpada Ox30030030 0x80080680 GxAGDAGDAG Ox30030030 0x8007000 Gx192282 Oxffferta 0x80080080 Gx0PAGDAG Ox30430530 0x80070080 Gx2000 70 71 72 73 74 75 76 77 78 79 80 82 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 $55 XPUSH IT Nacro push(arg) sw Sarg, Bx0($sp) eddi ssp. $sp, 4 end macro POP IT Macro popsary) eddi ssp. $sp, +4 w Sarg, Bx@($sp) end macro Ss7 St8 St9 ska Ski Son SSD Sfo Sra pc hi 10 * : Necro exit Usage: exit lacro exit u sv@, 10 syscall .end necro Line: 1 Column: 1 Shuw Line Numbers Run I/O File Edit Run Sellings Tools Help Run speed at max (no interaction) 1 Execute Copro 1 Cupruco Vam Number C547_macro.asm Value Szero Sve Sul Sal Saz Sa sta Stl St> st3 St4 St5 sta st3 1 l include "./cs47 nacro.asm. Z 3 data Ex10808800 4 var a: .byte 3x13 y Type: Ciar (8-bit) 5 var 5: .helt 3x3210 Type: Short (26-X 6 var 4: .byte 8x23 Type: Char (9-11) 7 var di word 3x 76543218 Type: int (32-bit) 8 9 push: .asci z "Pushing-> 99 pop: ascli2 "Papping - 10 char pipe: .ascitz"1" char ni asciiz "1" 12 13 .text 14 .globl main 15 0212 16 #these are all pseudo instruction 17 # HIPS natively supports only relative 18 address translation le.y. ib sse, 8x2345/59p)! 19 ID $56, var_a X Riso = var a'17: 20 IN $51, var_ Ris]) = var 1115:8) 21 ID $S2, var cy RS2) - var 17:21 22 IW $53, var d x Ris3) = /var d1115:8) 23 24 25 # PUS! the 50...4 to stack 26 print string push) 27 push(30) 28 print reg int($) 29 30 push($51) 31 print str(char papel 32 print l'egant (1) 33 34 push($s2) 35 print_str(char pipe! 36 print reg int($52) 37 38 push($s3) 39 print str(char pipe 10 print l'eg int($53) Ssa ss1 Ss2 553 SS4 1 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 18 19 20 21 22 23 14 24 25 26 27 28 29 30 31 0x80080000 x2000 8x38888888 0x80080080 GX2920 Ox30830830 0x80070080 GX8G186186 8x38888888 0x80080080 HAASAGMS Ox30030038 0x80080680 GxAGDAGDAG Ox30030030 0x0000000 HAAGMGRMS Ox30030030 0x80070080 GxAGDAGDAG Ox30030030 0x0000000 GxAGRAM Ox30030030 0x80080680 GxAGDAGDAG Ox30030030 0x8007000 Gx192282 Oxffferta 0x80080080 Gx0PAGDAG Ox30430030 Ox80030990 Gx2000 $55 S56 Ss7 sta St9 ska Ski Son SSP Sto Sra pc hi 10 Line: 1 Column: 1 Shuw Line Numbers Run I/O Clear File Edit Run Sellings Tools Help Run speed at max (no interaction) 1 Execute Copro 1 Cupruco Number C547_macro.asm Value Vans Szero #Push the 58...4 to stack print string gush) push($) print leg int($) Sve Svi 25 26 27 28 29 39 31 32 33 34 35 36 37 38 39 40 41 AZ 43 push() print_str(char pipe! print reg int($51) push($s2) print str(char pipe print reg int($s2) push($53) print_str(char pape! print reg int(53) Sal Saz Sa sta Sti St2 st3 St4 St.5 sta St7 Ssa ssl Ss2 553 S54 1 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 18 19 20 21 22 23 14 24 25 26 27 28 29 30 31 print strichar nl) 0x80080000 x2000 8x38888888 0x80080080 GX2920 Ox30830830 0x80070080 GX8G186186 8x38888888 0x80080080 HAASAGMS Ox30030038 0x80080680 GxAGDAGDAG Ox30030030 0x0000000 HAAGMGRMS Ox30030030 0x80070080 GxAGDAGDAG Ox30030030 0x0000000 GxAGRAM Ox30030030 0x80080680 GxAGDAGDAG Ox30030030 0x8007000 Gx192282 Oxffferta 0x80080080 Gx0PAGDAG Ox30430030 Ox80030990 Gx2000 $55 # pop the t8...4 lo steck print string pop) popiste print leg int($to) pop(st11 print_str(char pape} print leg int($ta) 15 46 47 48 49 50 51 52 53 54 55 56 57 58 59 69 61 popis:2 print str(char pipe print reg int($ta) popst3 print str(char pipe? print reg antists) print str(char nl) systent Exit exit Ss7 St8 St9 ska Ski Son SSD Sfo Sra pc ha 10 53 Line: 1 Column: 1 Shuw Line Numbers Run I/O File Edit Run Sellings Tools Help Run speed at max (no interaction) 1 Execute Copro 1 Cupruco Vam Number pa04.asm Value Szero --- Sve Sul 1 ---- MACRO DEFINITIONS z y Necro: print ser 3 y Usage: print stri address of the strings) acro print strisery 5 li sve, 4 x Systa call code for print str 6 la Sea, sargy Address of the string to print 7 syscall x Print the string 8 end macro Sal Saz Sa sta Stl St> st3 St4 St.5 sta st3 Ssa ssl Ss2 553 S54 1 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 18 19 20 21 22 23 14 24 25 26 27 28 29 30 31 0x80080000 x2000 8x38888888 0x80080080 GX2920 Ox30830830 0x80070080 GX8G186186 8x38888888 0x80080080 HAASAGMS Ox30030038 0x80080680 GxAGDAGDAG Ox30030030 0x0000000 HAAGMGRMS Ox30030030 0x80070080 GxAGDAGDAG Ox30030030 0x0000000 GX4Gpada Ox30030030 0x80080680 GxAGDAGDAG Ox30030030 0x8007000 Gx192282 Oxffferta 0x80080080 Gx0PAGDAG Ox30430530 0x80070080 Gx2000 19 Necroprin int 11 x Usage: print intisve!) 12 lacro print intisarg> 13 li Svo, 1 Systes cail code for printing 14 li se, argy Integer to print 15 syscall x Print the integer 16 end necro 17 18 X Necro : reedint 19 Usage: read Anve!) 29 Macro reed int(sreg) 21 li sva, 5 y Systa call for read in 22 Syscall 23 nave treg, $vo Integer to sove to new seory location 24 end macro 25 26 X Necro : reedint 27 Usage , read Anclave! of inputs) 28 Nacro print_reg int(sreg) 29 li sve, i Systen Cell for print reg int 30 nave $ab, Sreg w Integer to move to new lewory location 31 syscall # Print the reg in 32 enc necro 33 34 y NecroSep lo 35 Usage: Swap corsvar of inputs) 36 Nacro swap hila (Step, Steng2 37 nhi Stempi x Move froe ni register 38 nflo step2 X Move fra lo register 39 thi stenpz x Move Trov ni register 40 nt lo stempl x Move tro o register $55 Ss7 st S19 ska ski Son SSP Sfo Sra pc hi 10 Line: 1 Column: 1 Show line Numbers Run I/O File Edit Run Sellings Tools Help Run speed at max (no interaction) 1 Execute Copro 1 Cupruco a04 asm Number Value Vans Szero Li sve, 4 L 38, 35tra1f3 Syscall # This can be simplified, by calling print strisstrowe! Print the cow string, Sve Svi 57 58 59 60 61 SZ 53 li Sva, 4 l b, strL syscall # This can be simplified, by calling print strisstro! y Print the lo value 55 56 67 Li sve, 4 la sao, sstrEquel syscall # This can be simplified, by calling print strisstrEqual! Y Print the equel string '=' Sal Saz Sa sta Sti St2 st3 St4 St.5 sta nflo sti printreg int sti) end macro y Print Cie reg int sti Vacro lwa (sreg, sui, SLL) Lui $res. $ui ori reg. reg. $14 .end Macro Ssa ssl Ss2 553 S54 1 1 2 3 4 5 6 7 8 9 16 11 12 13 14 15 16 17 18 19 20 21 22 23 14 24 25 26 27 28 29 30 31 0x80080000 x2000 8x38888888 0x80080080 GX2920 Ox30830830 0x80070080 GX8G186186 8x38888888 0x80080080 HAASAGMS Ox30030038 0x80080680 GxAGDAGDAG Ox30030030 0x0000000 HAAGMGRMS Ox30030030 0x80070080 GxAGDAGDAG Ox30030030 0x0000000 GX4Gpada Ox30030030 0x80080680 GxAGDAGDAG Ox30030030 0x8007000 Gx192282 Oxffferta 0x80080080 Gx0PAGDAG Ox30430530 0x80070080 Gx2000 70 71 72 73 74 75 76 77 78 79 80 82 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 $55 XPUSH IT Nacro push(arg) sw Sarg, Bx0($sp) eddi ssp. $sp, 4 end macro POP IT Macro popsary) eddi ssp. $sp, +4 w Sarg, Bx@($sp) end macro Ss7 St8 St9 ska Ski Son SSD Sfo Sra pc hi 10 * : Necro exit Usage: exit lacro exit u sv@, 10 syscall .end necro Line: 1 Column: 1 Shuw Line Numbers Run I/OStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started