Demo entry 6768132

nasm

   

Submitted by anonymous on Nov 01, 2018 at 19:17
Language: NASM. Code size: 1.0 kB.

;Chris Mitchell
;Problem 4.2
;Write a program to calculate grades
;first add up all possible points
;then add up all points the student got
;divide studentTotal / total to get grade
;10-2718
 
section .data
test1Score: dd 25
test1Possible: dd 30
test2Score: dd 89
test2Possible: dd 100
test3Score: dd 49
test3Possible: dd 50
test4Score: dd 80
test4Possible: dd 150

section .bss
studentTotal: resd 1
total: resd 1
grade: resd 1

section .text
global _main
_main:

;Student Total
mov eax, 0
mov eax, [test1Score]
add eax, [test2Score]
add eax, [test3Score]
add eax, [test4Score]
mov [studentTotal], eax


;tests total
mov eax, 0
mov eax, [test1Possible]
add eax, [test2Possible]
add eax, [test3Possible]
add eax, [test4Possible]
mov [total], eax

;Now we have values for studentTotal, and total. Divide studentTotal/total = grade
mov edx, 0
mov eax, dword [studentTotal]
div dword [total]
mov dword [grade], eax

;Grade is now in eax

mov eax, 1
mov ebx, 0
int 80h

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).