-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloops.asm
63 lines (48 loc) · 1.16 KB
/
loops.asm
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
; Define some constants
.def counter r0 ; counter register
.def calc1 r1 ; used for calculations
.def calc2 r2
.def s_one r4 ; static one
.def s_zero r5 ; static zero
.label entry_addr
.label setup
; setup registers
loadi counter, 100
loadi s_one, 1
loadi s_zero, 0
; print the welcome and description messages
push t_address, msg_welcome
push t_size, 10
push t_syscall, sys_write
syscall
push t_address, msg_description
push t_size, 39
push t_syscall, sys_write
syscall
.label loop
; print the current number
push t_register, counter
push t_syscall, sys_puts
syscall
; exit if zero was reached
cmp counter, s_zero
jz _exit
; decrement the counter
sub counter, s_one
; repeat
jmp loop
; exit the program
.label _exit
; write the goodbye message
push t_address, msg_goodbye
push t_size, 10
push t_syscall, sys_write
syscall
; exit the program
push byte, 0
push t_syscall, sys_exit
syscall
; string constants
.db msg_welcome 10 "Welcome!!\n"
.db msg_description 39 "This program counts from 100 down to 0\n"
.db msg_goodbye 10 "Goodbye!!\n"