-
Notifications
You must be signed in to change notification settings - Fork 0
/
ECOAR_RISCV_Musab_Alsaifi.asm
153 lines (126 loc) · 2.73 KB
/
ECOAR_RISCV_Musab_Alsaifi.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Musab Alsaifi
*/
.data
prompt_b: .string "Enter the value for Blue value: "
prompt_g: .string "Enter the valur for Green value: "
prompt_r: .string "Enter the value for Red value: "
prompt_dx: .string "Enter the dx direction: "
prompt_dy: .string "Enter the dy direction: "
#Const.
.eqv WIDTH 512
.eqv HEIGHT 256
.eqv PRINT_STR 4
.eqv READ_INT 5
.eqv EXIT_0 10
.eqv ADDRESS 268697600
.eqv SLEEP 32
.text
#print prompt_r
li a7, PRINT_STR
la a0, prompt_r
ecall
#read and store the value for Red
li a7, READ_INT
ecall
slli s0, a0, 16
#print prompt_g
li a7, PRINT_STR
la a0, prompt_g
ecall
#read and store the value for Grean
li a7, READ_INT
ecall
slli a0, a0, 8
add s0, s0, a0
#print prompt_b
li a7, PRINT_STR
la a0, prompt_b
ecall
#read and store the value for Blue
li a7, READ_INT
ecall
add s0, s0, a0
#print prompt_dx
li a7, PRINT_STR
la a0, prompt_dx
ecall
#read and store the value for dx
li a7, READ_INT
ecall
mv s3, a0
#print prompt_dy
li a7, PRINT_STR
la a0, prompt_dy
ecall
#read and store the value for dy
li a7, READ_INT
ecall
mv s4, a0
li s5, ADDRESS
#bytes per line
li t0, WIDTH
slli t0, t0, 2
#number of lines to skip to get to the middle line
li t1, HEIGHT
srli t1, t1, 1
mv s6, t1
li t2, -1
#number of divisions to go to the middle of the height. So, if height is 256, then half of it is 128 which is 2^7
loop:
beqz t1, middle
srli t1, t1, 1
addi t2, t2, 1
j loop
#go to the middle of the height
middle:
sll t3, t0, t2 #t0 * 7, so now we are at the right of middle screen
li t1, WIDTH
slli t1, t1, 1 #divide width by 2
sub t3, t3, t1 #substract half of the width to go to the middle of the screen (0, 0)
add s5, s5, t3 #go to point (0, 0) which is the middle of the screen
li s7, WIDTH
srli s7, s7, 1 #store in s7 half of the width cz we need to use it later
#implementation of bresenham algorithm
sub t2, s4, s3 #e
slli t2, t2, 1
li t3, 0 #x
li t4, 0 #y
li t5, 4
li a7, SLEEP
li a0, EXIT_0
neg_x:
bgtz s3, neg_y
neg t5, t5
neg s3, s3
neg_y:
bgtz s4, while
neg t0, t0
neg s4, s4
while:
bne t4, s6, check_x
neg t4, t4
neg t0, t0
check_x:
bne t3, s7, draw
neg t3, t3
neg t5, t5
if:
bltz t2, cont
sub s5, s5, t0
addi t4, t4, 1
sub t2, t2, s3
j while
cont:
addi t3, t3, 1
add s5, s5, t5
add t2, t2, s4
j while
#Drawing pixal
draw:
ecall
sw s0, (s5)
j if
exit:
li a7, EXIT_0
ecall