Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write in C++ an assembler for a subset of the MIPS instruction set. It should read the assembly file from standard input and write the

Write in C++ an assembler for a subset of the MIPS instruction set. It should read the assembly file from standard input and write the machine code to standard output. It must recognize the directives: .text , .data, .word, .space n. The assembler needs to read the I-Instruction format lw, sw, beq, and bne and identify the labels.

.text

addu $s0,$zero,$zero # s0 = 0

addu $s1,$zero,$zero # s1 = 0

addiu $v0,$zero,5 # v0 = read value

syscall

sw $v0,n($gp) # M[n] = v0

L1: lw $s2,n($gp) # s2 = M[n]

slt $t0,$s1,$s2 # if s1 >= s2 then

beq $t0,$zero,L2 # goto L2

addiu $v0,$zero,5 # v0 = read value

syscall

addu $s0,$s0,$v0 # s0 += v0

addiu $s1,$s1,1 # s1 += 1

j L1 # goto L2

L2: addu $a0,$s0,$zero # a0 = s0

addiu $v0,$zero,1 # print a0

syscall

addiu $v0,$zero,10 # exit

syscall

.data

n: .word 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions