In MIPS / MARS
Be able to input to display your name and show how many hours you worked this week, hourly wage.
Example:
Please enter your name: John Doe
You entered: John Doe
Please enter number of hours worked: 40
You entered: 40
Please enter your hourly wage: $15
You entered: $15
Your paycheck is $600 for the week.
Code-
===================================================================
.data
name_prompt:
.asciiz "Please enter your name: "
hours_prompt:
.asciiz "Please enter number of hours worked: "
rate_prompt:
.asciiz "Please enter your hourly wage: $"
message:
.asciiz "You entered: "
rate_message:
.asciiz "You entered: $"
paycheck_1:
.asciiz "Your paycheck is $"
paycheck_2:
.asciiz " for the week."
name:
.space 20
.text
main:
#Print name_prompt
li $v0, 4
la $a0, name_prompt
syscall
#Read name
li $v0, 8
la $a0, name
li $a1, 40
syscall
#Print message
li $v0, 4
la $a0, message
syscall
#Print name
li $v0, 4
la $a0, name
syscall
#Print hours_prompt
li $v0, 4
la $a0, hours_prompt
syscall
#Reading Hours
li $v0, 5
syscall
#Storing hours worked in $t0
move $t0, $v0
#Print message
li $v0, 4
la $a0, message
syscall
#Printing the hours worked
li $v0, 1
move $a0, $t0
syscall
#Storing hours worked in $t0 again for later multiplication
move $t0, $a0
#Print rate_prompt
li $v0, 4
la $a0, rate_prompt
syscall
#Reading rate
li $v0, 5
syscall
#Storing rate or hourly wage in $t1
move $t1, $v0
#Print message
li $v0, 4
la $a0, rate_message
syscall
#Printing the hours worked
li $v0, 1
move $a0, $t1
syscall
#Storing hours worked in $t1 again for later multiplication
move $t0, $a0
#calculating paycheck by multiplying hourly wage and hours
worked
mult $t0, $t1
mflo $s0
#Printing paycheck line 1
li $v0, 4
la $a0, paycheck_1
syscall
#Printing calculated paycheck
li $v0, 1
add $a0, $zero, $s0
syscall
#Printing remaining paycheck line
li $v0, 4
la $a0, paycheck_2
syscall
#Telling system that the main is ended here
li $v0, 10
syscall
=============================================================
mflo means move from low register as mult stores the result in one of the two registers lo and hi and you can store result from the registers to another register to be used later
Get Answers For Free
Most questions answered within 1 hours.