Problem 1 (40 points) Write a MIPS program (which must be named as \"hw4_probls\
ID: 3732835 • Letter: P
Question
Problem 1 (40 points) Write a MIPS program (which must be named as "hw4_probls") that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will be between 2 and 36, and the digits for the values will be in set [0...9, a...z]. You can assume that no overflow will occur and the value is valid in the given base. An example run will be: Enter a base (between 2 and 36 in decimal): 2 Enter a number in base 2: 110 The value in decimal is: 6 Then you need to test program using the above case and the following cases and include the results in the pdf file you need to submit. Enter a base (between 2 and 36 in decimal): 10 Enter a number in base 10: 13579 The value in decimal is: 13579 Enter a base (between 2 and 36 in decimal): 16 Enter a number in base 16: abcdef0 The value in decimal is: 180150000 Hint: The input and output can be done using syscalls in MIPS that are given on p. A-44.Explanation / Answer
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .rdata .align 2 $LC0: .ascii "Enter a base(between 2 and 36): " .align 2 $LC1: .ascii "%d " .align 2 $LC2: .ascii "Enter Number : " .align 2 $LC3: .ascii "%s " .align 2 $LC4: .ascii "%d " .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,152,$31 # vars= 120, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-152 sw $31,148($sp) sw $fp,144($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 sw $0,28($fp) lw $2,%got($LC0)($28) nop addiu $4,$2,%lo($LC0) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) addiu $2,$fp,136 move $5,$2 lw $2,%got($LC1)($28) nop addiu $4,$2,%lo($LC1) lw $2,%call16(__isoc99_scanf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,__isoc99_scanf 1: jalr $25 nop lw $28,16($fp) nop lw $2,%got($LC2)($28) nop addiu $4,$2,%lo($LC2) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) addiu $2,$fp,36 move $5,$2 lw $2,%got($LC3)($28) nop addiu $4,$2,%lo($LC3) lw $2,%call16(__isoc99_scanf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,__isoc99_scanf 1: jalr $25 nop lw $28,16($fp) sw $0,24($fp) b $L2 nop $L5: lw $2,24($fp) addiu $3,$fp,24 addu $2,$3,$2 lb $2,12($2) nop sw $2,32($fp) li $3,122 # 0x7a lw $2,32($fp) nop subu $2,$3,$2 bltz $2,$L3 nop li $3,122 # 0x7a lw $2,32($fp) nop subu $2,$3,$2 slt $2,$2,27 beq $2,$0,$L3 nop lw $3,136($fp) lw $2,28($fp) nop mult $3,$2 lw $2,32($fp) nop addiu $2,$2,-87 mflo $3 addu $2,$3,$2 sw $2,28($fp) b $L4 nop $L3: li $3,57 # 0x39 lw $2,32($fp) nop subu $2,$3,$2 bltz $2,$L4 nop li $3,57 # 0x39 lw $2,32($fp) nop subu $2,$3,$2 slt $2,$2,11 beq $2,$0,$L4 nop lw $3,136($fp) lw $2,28($fp) nop mult $3,$2 lw $2,32($fp) nop addiu $2,$2,-48 mflo $3 addu $2,$3,$2 sw $2,28($fp) $L4: lw $2,24($fp) nop addiu $2,$2,1 sw $2,24($fp) $L2: addiu $2,$fp,36 move $4,$2 lw $2,%call16(strlen)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,strlen 1: jalr $25 nop lw $28,16($fp) move $3,$2 lw $2,24($fp) nop sltu $2,$2,$3 bne $2,$0,$L5 nop lw $5,28($fp) lw $2,%got($LC4)($28) nop addiu $4,$2,%lo($LC4) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) move $2,$0 move $sp,$fp lw $31,148($sp) lw $fp,144($sp) addiu $sp,$sp,152 j $31 nop .set macro .set reorder .end main .size main, .-main .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.