3

Click here to load reader

Sample Assembly

Embed Size (px)

Citation preview

Page 1: Sample Assembly

################################################################################# Monica Torres CS 2318-251, Assignment 2 Part 1 Program D #### #### Description: This program takes in 2 exam grades and a final grade #### and computes the weighted average score. #################################################################################

.dataprompte1: .asciiz "Enter integer score for Exam 1: "prompte2: .asciiz "\nEnter integer score for Exam 2: "promptfs: .asciiz "\nEnter integer score for Final: "result: .asciiz "\nWeighted Average Score is: "

.align 2e1score: .space 4e2score: .space 4finscore: .space 4

.text

.globl main

main:

li $v0, 4la $a0, prompte1 # prompt for exam 1 scoresyscallli $v0, 5 # reads in integersyscallla $t0, e1scoresw $v0, 0($t0) # saves it to memory

variable

li $v0, 4la $a0, prompte2syscallli $v0, 5syscall # reads in 2nd integer la $t0, e2scoresw $v0, 0($t0)

li $v0, 4la $a0, promptfssyscallli $v0, 5syscall # reads in final score la $t0, finscoresw $v0, 0($t0)

Page 2: Sample Assembly

la $t0, e1scorelw $t1, 0($t0)sll $t1, $t1, 8 # $t1 should hold e1score x

256 (2^8)li $t2, 2016 # $t2 has 2016?div $t1, $t2 # dividing (e1score x

256) / 2016mflo $t1 # stores the corresponding

answer

la $t0, e2scorelw $t2, 0($t0) #loads the second scoreli $t3, 24mult $t2, $t3mflo $t2sra $t2, $t2, 6 # should divide whats in t2

by 64

la $t0, finscorelw $t3, 0($t0)sra $t3, $t3, 1 # should divide whats in t3

by 2

add $t4, $t1, $t2 # t4 = t1 + t2

add $t5, $t4, $t3 # t5 = t4 + t3

li $v0, 4la $a0, resultsyscallli $v0, 1move $a0, $t5syscall

li $v0, 10syscall