Answer to Question #322511 in Assembler for kea

Question #322511

consider the following program :

void main()

{

int i;

printf(“Please enter an integer: ”);

scanf(%d,&i);

printf(“\n”);

switch(i) {

case 1: printf("I am one.\n"); break;

case 2: printf("I am two.\n"); break;

default: printf("I am neither one, nor two.\n"); }

}

///////////////////////////////////////////////////////////////////////

What you see below is part of the assembly code of the above program. Complete it using MIPS assemby and use “jump address table“ method.

.data

prmt: .asciiz "Please enter an integer: "

nline: .byte '\n'

.text

.globl main

main:

li $v0,4

la $a0,prmt

syscall

li $v0,5

syscall

addi $a0,$v0,0

li $v0,1

syscall

la $t0,nline

li $v0,11

syscall

# place your switch statement's assembly program here

li $v0,10

syscall


1
Expert's answer
2022-04-02T09:59:26-0400
# MARS/MIPS
###############################################################
.data
prmt: .asciiz "Please enter an integer: "
nline: .asciiz    "\n"
msg1:     .asciiz    "I am one\n"
msg2:     .asciiz    "I am two\n"
msg3:     .asciiz    "I am neither one, nor two\n"

# create the jmp_tab This is a string addresses
jump_msg1:    .word msg1
jump_msg2:    .word msg2
jump_msg3:    .word msg3

.text
.globl main
main:
li $v0,4
la $a0,prmt
syscall

li $v0,5        # reads int
syscall
move $t0,$v0    # save int
addi $t0,$t0,-1

addi $a0,$v0,0  # print int
li $v0,1
syscall

    li $t3,2
    ble $t0,$t3,l3
    li $t0,2
l3:
    sll $t0,$t0,2    # multyply by 4 to properly index the 32-bit jmp tabl

    la $a0,nline
    li $v0,11
    syscall

    la $t1,    jump_msg1    # address of jmp_msgl
    add $t0,$t1,$t0        # address of element i in the jmp tab

    # read elementi in the jmp_tab
    lw $a0,0($t0)    # Tis is the address of i-th string in jmp_tab
    li $v0,4        # print string
    syscall            # make the syscall

    li $v0,10
    syscall

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS