-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_2_8.s
68 lines (58 loc) · 2.3 KB
/
lab_2_8.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#################################################
#
# lab2_8a.s
# 32 / 32 bit division
#
#################################################
#############################
# Text Segment #
#############################
.text
.globl main
main:
# Input dividend
la $a0, dividend # Load address of "Enter dividend:" string
li $v0, 4 # Load print string syscall code
syscall # Prompt for dividend
li $v0, 5 # Load read integer syscall code
syscall # Read dividend
move $t0, $v0 # Move dividend to $t0
# Input divisor
la $a0, divisor # Load address of "Enter divisor:" string
li $v0, 4 # Load print string syscall code
syscall # Prompt for divisor
li $v0, 5 # Load read integer syscall code
syscall # Read divisor
move $t1, $v0 # Move divisor to $t1
# Perform division
div $t0, $t1 # Divide dividend by divisor
# Output quotient
la $a0, quotient # Load address of "Quotient is: " string
li $v0, 4 # Load print string syscall code
syscall # Display "quotient is :"
move $a0, $t0 # Move quotient to $a0
li $v0, 1 # Load print integer syscall code
syscall # Display quotient
# Output remainder
la $a0, remainder # Load address of "Remainder is: " string
li $v0, 4 # Load print string syscall code
syscall # Display "remainder is :"
move $a0, $t1 # Move remainder to $a0
li $v0, 1 # Load print integer syscall code
syscall # Display remainder
# Output newline
la $a0, endl # Load address of newline string
li $v0, 4 # Load print string syscall code
syscall # Print newline
# Exit
li $v0, 10 # Load exit syscall code
syscall # Exit
#############################
# Data Segment #
#############################
.data
dividend: .asciiz "Enter dividend:"
divisor: .asciiz "Enter divisor:"
endl: .asciiz "\n"
quotient: .asciiz "Quotient is: "
remainder: .asciiz "Remainder is: "