Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# timetemplate.asm a ) Rewrite the following C function as an assembly - language subroutine with the same behavior. void delay ( int ms )

# timetemplate.asm
a) Rewrite the following C function as an assembly-language subroutine with the same behavior.
void delay( int ms )/* Wait a number of milliseconds, specified by the parameter value. */
{
int i;
while (ms>0)
{
ms=ms-1;
??** Executing the following for loop should take 1ms*/
for i*=0;i4711;i=i+1* The constant 4711 must be easy to change! */
{
/* Do nothing. */
}
}
}
Important note for all subroutines (reprise): When a subroutine returns, registers $s0-$s7,$gp, $sp,
$fp, and $ ra must have the same contents as when the subroutine was called. If a subroutine uses
any of these registers, the original contents must be saved, and restored before the subroutine
returns. As a special case, the contents of registers $k0 and $k1 may not be modified at all; these
registers are reserved for interrupt-handling code. All other register contents may be modified by
any subroutine.
b) Replace the three-line delay subroutine from the previous Assignment, with your own
assembly-language subroutine de lay in file timetemplate.asm.
c) Test your program using MARS. Adjust the constant in the for loop to get a delay of 1000ms
when de lay is called with a parameter value of 1000, and a delay of 3000ms when de lay is called
with a parameter value of 3000..macro PUSH (%reg)
addi $sp,$sp,-4
sw %reg,0($sp)
.end_macro
.macro POP (%reg)
lw %reg,0($sp)
addi $sp,$sp,4
.end_macro
.data
.align 2
mytime: .word 0x5957
timstr: .ascii "text more text lots of text\0"
.text
main:
# print timstr
la $a0,timstr
li $v0,4
syscall
nop
# wait a little
li $a0,2
jal delay
nop
# call tick
la $a0,mytime
jal tick
nop
# call your function time2string
la $a0,timstr
la $t0,mytime
lw $a1,0($t0)
jal time2string
nop
# print a newline
li $a0,10
li $v0,11
syscall
nop
# go back and do it all again
j main
nop
# tick: update time pointed to by $a0
tick: lw $t0,0($a0) # get time
addiu $t0,$t0,1 # increase
andi $t1,$t0,0xf # check lowest digit
sltiu $t2,$t1,0xa # if digit a, okay
bnez $t2,tiend
nop
addiu $t0,$t0,0x6 # adjust lowest digit
andi $t1,$t0,0xf0 # check next digit
sltiu $t2,$t1,0x60 # if digit 6, okay
bnez $t2,tiend
nop
addiu $t0,$t0,0xa0 # adjust digit
andi $t1,$t0,0xf00 # check minute digit
sltiu $t2,$t1,0xa00 # if digit a, okay
bnez $t2,tiend
nop
addiu $t0,$t0,0x600 # adjust digit
andi $t1,$t0,0xf000 # check last digit
sltiu $t2,$t1,0x6000 # if digit 6, okay
bnez $t2,tiend
nop
addiu $t0,$t0,0xa000 # adjust last digit
tiend: sw $t0,0($a0) # save updated result
jr $ra # return
nop
# you can write your code for subroutine "hexasc" below this line
#
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions

Question

Where are C program variables stored?

Answered: 1 week ago