-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.asm
More file actions
1544 lines (1317 loc) · 37.8 KB
/
main.asm
File metadata and controls
1544 lines (1317 loc) · 37.8 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.data 0x10000000
strMenuWait: .asciiz "\n\n\n\n Please wait ....... \n\n\n\n\n"
strMenuHr: .asciiz " \n"
strHistogramHr: .asciiz " \n\t"
strMenuOpts: .asciiz "Select an option: \n"
srtMenuOp1: .asciiz "1 - Reset image \n"
strMenuOp2: .asciiz "2 - Rotate colors \n"
strMenuOp3: .asciiz "3 - Rotate image 90 degree left \n"
strMenuOp4: .asciiz "4 - Rotate image 90 degree right \n"
strMenuOp5: .asciiz "5 - Mirror image through x axis \n"
strMenuOp6: .asciiz "6 - Mirror image through y axis \n"
strMenuOp7: .asciiz "7 - Invert colors \n"
strMenuOp8: .asciiz "8 - Greyscale \n"
strMenuOp9: .asciiz "9 - Greenscale \n"
strMenuOp10: .asciiz "10 - First byte Histogram (for greyscale images)\n"
strMenuOp11: .asciiz "11 - Pixel average filter\n"
strMenuOp12: .asciiz "12 - Contrast adjust (for greyscale images)\n"
strMenuOp13: .asciiz "13 - Contrast adjust (for colored images)\n"
strMenuOp14: .asciiz "Other - Exit \n"
strPrintHistogramHyphen: .asciiz "\t - \t"
strPrintHistogramHeader: .asciiz "Image Histogram: \n\n | Intensity | Ocurrences | \n\t"
strErrOpenFile: .asciiz "Error opening the file. Are you sure that the name is correct?\n"
strErrReadFile: .asciiz "Error reading the file. Are you sure that it is a bmp compatible file? \n"
filename: .asciiz "img.bmp"
header: .space 54 #54 bytes is the standard header size for a true color bmp image
# to read
# The pixel size must bit 3 bytes (24bits) too.
# Uncompressed image as well
.text
main:
jal loadImage
#Will read the image at the same directory as mars is located and loads and copy at $sp and
# $gp. The idea behind it is making two copies is that one of these will be the displayed
# image with (or without) filters applied. If the user chooses he can reset the image to
# the the original state wich means a copy of the data at $sp to $gp.
add $s0, $v0, $zero
add $s1, $v1, $zero
menuOptsScr:
li $v0, 4
la $a0, strMenuHr
syscall
li $v0, 4
la $a0, strMenuOpts
syscall
li $v0, 4
la $a0, srtMenuOp1
syscall
li $v0, 4
la $a0, strMenuOp2
syscall
li $v0, 4
la $a0, strMenuOp3
syscall
li $v0, 4
la $a0, strMenuOp4
syscall
li $v0, 4
la $a0, strMenuOp5
syscall
li $v0, 4
la $a0, strMenuOp6
syscall
li $v0, 4
la $a0, strMenuOp7
syscall
li $v0, 4
la $a0, strMenuOp8
syscall
li $v0, 4
la $a0, strMenuOp9
syscall
li $v0, 4
la $a0, strMenuOp10
syscall
li $v0, 4
la $a0, strMenuOp11
syscall
li $v0, 4
la $a0, strMenuOp12
syscall
li $v0, 4
la $a0, strMenuOp13
syscall
li $v0, 4
la $a0, strMenuOp14
syscall
li $v0, 5
syscall
add $t0, $v0, $zero
li $v0, 4
la $a0, strMenuWait
syscall
beq $t0, 1, resetImageCall
beq $t0, 2, rotateColorsCall
beq $t0, 3, rotate90lCall
beq $t0, 4, rotate90rCall
beq $t0, 5, flipXCall
beq $t0, 6, flipYCall
beq $t0, 7, invertColorsCall
beq $t0, 8, greyScaleCall
beq $t0, 9, greenScaleCall
beq $t0, 10, histogramCall
beq $t0, 11, pixelAverageCall
beq $t0, 12, contrastAdjustCall
beq $t0, 13, contrastAdjustColoredCall
bgt $t0, 14, endProgram
#end menuOptsScr
resetImageCall:
add $a0, $s0, $zero
add $a1, $s1, $zero
jal dispOriginal
j menuOptsScr
#end resetImageCall
rotateColorsCall:
#Will read the image from $a0, which is $gp int this case, and will apply the rotateColors filter.
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal rotateColors
j menuOptsScr
#end rotateColorsCall
rotate90lCall:
#Will read the image from $a0, which is $gp int this case, and will rotate the image 90 degrees to the left.
#The thing here is transpose the image matrix first and then flip it through the x axis.
# Use: $a0 and $a1 which are the image properties and data, respectively.
lw $a0, 4($s0)
la $a1, 0x10008000
jal rotate90l
add $a0, $s0, $zero
la $a1, 0x10008000
jal flipX
j menuOptsScr
#end rotate90lCall
rotate90rCall:
#Will read the image from $a0, which is $gp int this case, and will rotate the image 90 degrees to the right.
#The thing here is the same as rotate90l.
# Use: $a0 and $a1 which are the image properties and data, respectively.
lw $a0, 4($s0)
la $a1, 0x10008000
jal rotate90r
add $a0, $s0, $zero
la $a1, 0x10008000
jal flipX
j menuOptsScr
#end rotate90rCall
flipXCall:
#Will read the image from $a0, which is $gp int this case, and will flip the image through the x axis
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal flipX
j menuOptsScr
#end rotateXCall
flipYCall:
#Will read the image from $a0, which is $gp int this case, and will flip the image through the y axis
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal flipY
j menuOptsScr
#end rotateXCall
invertColorsCall:
#Will read the image from $a0, which is $gp int this case, and will apply the invert colors filter.
#The equation being used is:
# R = (255-R); G = (255-G); B = (255-B);
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal invertColors
j menuOptsScr
#end invertColorsCall
greyScaleCall:
#Will read the image from $a0, which is $gp int this case, and will apply the invert colors filter.
#The equation being used is:
# I = 0,2989*R + 0,5870*G + 0,1140*B
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal greyScale
j menuOptsScr
#end invertColorsCall
greenScaleCall:
#Will read the image from $a0, which is $gp int this case, and will apply the invert colors filter.
#Some nice effected obtained by the mistaken application of the greyscale filter.
#The equation being used is:
# I = 0,2989*R + 0,5870*G + 0,1140*B
#With the wrong use of the mips instruction set, of course.
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal greenScale
j menuOptsScr
#end invertColorsCall
histogramCall:
#Will read the image from $a0, which is $gp int this case, and will analyse the image and display in Run I/O container
# the obtained results.
#The ideia behind an histogram is to collect the number of ocurrences for each color in a image.
#Since the colored imaged has a large number of colors, the application will collect only the first byte to analyse, meaning
# that the image has to be 256 color max. Wich a grayscale certainly is.
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal histogram
j menuOptsScr
#end histogramCall
pixelAverageCall:
#Will read the image from $a0, which is $gp int this case, and will apply the pixel average filter.
#The procedure is collect the byte and substitute it with the average of the 8 neighbor pixels.
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal pixelAverage
j menuOptsScr
#end pixelAverageCall
contrastAdjustCall:
#Will read the image from $a0, which is $gp int this case, and will apply the pixel average filter.
#The equation being used is:
# Inew(x,y) = [I(x,y) - Ilow] * [255 / (Ihigh - Ilow)]
#The problem is that for each pixel we need to make a difference subtituition, so, apply this filter to
# a grayscale simplify the whole thing. This function works right with a grayscale image.
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal contrastAdjust
j menuOptsScr
#end contrastAdjustCall
contrastAdjustColoredCall:
#Well, the fact is that i ended this with a large time before the deadline, so lets do it for a colored image to.
#To save some time and neurons, i used the contrastAdjust functon to adjust only one byte per iteration and
# rotated the colors to make that same byte have the next color to iterate.
#Same equation as before but with the color rotation thing.
# Use: $a0 and $a1 which are the image properties and data, respectively.
add $a0, $s0, $zero
la $a1, 0x10008000
jal contrastAdjustColored
add $a0, $s0, $zero
add $a1, $s1, $zero
jal rotateColors
add $a0, $s0, $zero
la $a1, 0x10008000
jal contrastAdjustColored
add $a0, $s0, $zero
add $a1, $s1, $zero
jal rotateColors
add $a0, $s0, $zero
la $a1, 0x10008000
jal contrastAdjustColored
add $a0, $s0, $zero
add $a1, $s1, $zero
jal rotateColors
j menuOptsScr
#end contrastAdjustColoredCall
add $a0, $s0, $zero
add $a1, $s1, $zero
jal endProgram
#Will terminate the program and will dislocate the $sp to the beggining place.
#The thing passing arguments to this function is that the function needs to know the shift amount in the $sp.
#end main
contrastAdjustColored:
# Register usage:
# t0: data info address backup
# t1: Image address beggining address backup
# t2: Image iterative address
# t3: RGB index (0 ~ 2)
# t4: Image index
# t5: Image max number of iterations
# t6: Max intensity
# t7: Minimum intensity
# t8: Loaded byte
# t9: backup of s
add $sp, $sp, -32
add $t9, $sp, $zero
sw $s0, 0($t9)
sw $s1, 4($t9)
sw $s2, 8($t9)
sw $s3, 12($t9)
sw $s4, 16($t9)
sw $s5, 20($t9)
sw $s6, 24($t9)
sw $s7, 28($t9)
add $t0, $a0, $zero #t0: data info address backup
add $t1, $a1, $zero #t1: Image address beggining address backup
li $t3, 0
lw $t5, 4($t0)
lw $t6, 8($t0)
mul $t5, $t5, $t6 #t5: Image max number of iterations
add $t2 $t1, $zero #t2: Image iterative address
seekBorderValuesColored:
li $t4, 0 #t4: Image index
li $t6, 0 #t6: Max intensity
li $t7, 255 #t7: Minimum intensity
loop_seekBorderValuesColored:
beq $t4, $t5, end_loop_seekBorderValuesColored
lbu $t8, 0($t2)
bgt $t8, $t6, maximum_seekBorderValuesColored
blt $t8, $t7, minimum_seekBorderValuesColored
j iterate_seekBorderValuesColored
maximum_seekBorderValuesColored:
add $t6, $t8, $zero
j iterate_seekBorderValuesColored
#end maximum_seekBorderValuesColored
minimum_seekBorderValuesColored:
add $t7, $t8, $zero
j iterate_seekBorderValuesColored
#end minimum_seekBorderValuesColored
iterate_seekBorderValuesColored:
#end
add $t2, $t2, 4
add $t4, $t4, 1
j loop_seekBorderValuesColored
end_loop_seekBorderValuesColored:
#end seekBorderValuesColored
color_contrastAdjustColored:
add $t2, $t1, $zero
li $t4, 0
#Inew(x,y) = [I(x,y) - Ilow] * [255 / (Ihigh - Ilow)]
loop_coolor_contrastAdjustColored:
beq $t4, $t5, fim_loop_coolor_contrastAdjustColored
lbu $t8, 0($t2)
sub $t8, $t8, $t7 #=[I(x,y) - Ilow]
sub $s1, $t6, $t7 #=(Ihigh - Ilow)
li $s2, 255 #=255
div $s1, $s2, $s1 # =[255 / (Ihigh - Ilow)]
mul $t8, $t8, $s1
sb $t8, 0($t2)
add $t4, $t4, 1
add $t2, $t2, 4
j loop_coolor_contrastAdjustColored
fim_loop_coolor_contrastAdjustColored:
#fim
#end color_contrastAdjustColored
lw $s0, 0($t9)
lw $s1, 4($t9)
lw $s2, 8($t9)
lw $s3, 12($t9)
lw $s4, 16($t9)
lw $s5, 20($t9)
lw $s6, 24($t9)
lw $s7, 28($t9)
add $sp, $sp, 32
jr $ra
#end contrastAdjustColored
contrastAdjust:
# Register usage:
# t0: data info address backup
# t1: Image address beggining address backup
# t2: Image iterative address
# t3: RGB index (0 ~ 2)
# t4: Image index
# t5: Image max number of iterations
# t6: Max intensity
# t7: Minimum intensity
# t8: Loaded byte
# t9: backup of s
add $sp, $sp, -32
add $t9, $sp, $zero
sw $s0, 0($t9) #3
sw $s1, 4($t9) #index for sll loop
sw $s2, 8($t9)
sw $s3, 12($t9)
sw $s4, 16($t9)
sw $s5, 20($t9)
sw $s6, 24($t9)
sw $s7, 28($t9)
add $t0, $a0, $zero #t0: data info address backup
add $t1, $a1, $zero #t1: Image address beggining address backup
li $t3, 0
lw $t5, 4($t0)
lw $t6, 8($t0)
mul $t5, $t5, $t6 #t5: Image max number of iterations
add $t2 $t1, $zero #t2: Image iterative address
seekBorderValues:
li $t4, 0 #t4: Image index
li $t6, 0 #t6: Max intensity
li $t7, 255 #t7: Minimum intensity
loop_seekBorderValues:
beq $t4, $t5, end_loop_seekBorderValues
lbu $t8, 0($t2)
bgt $t8, $t6, maximum_seekBorderValues
blt $t8, $t7, minimum_seekBorderValues
j iterate_seekBorderValues
maximum_seekBorderValues:
add $t6, $t8, $zero
j iterate_seekBorderValues
#end maximum_seekBorderValues
minimum_seekBorderValues:
add $t7, $t8, $zero
j iterate_seekBorderValues
#end minimum_seekBorderValues
iterate_seekBorderValues:
#end
add $t2, $t2, 4
add $t4, $t4, 1
j loop_seekBorderValues
end_loop_seekBorderValues:
#end seekBorderValues
color_contrastAdjust:
add $t2, $t1, $zero
li $t4, 0
#Inew(x,y) = [I(x,y) - Ilow] * [255 / (Ihigh - Ilow)]
loop_coolor_contrastAdjust:
beq $t4, $t5, fim_loop_coolor_contrastAdjust
lbu $t8, 0($t2)
sub $t8, $t8, $t7 #=[I(x,y) - Ilow]
sub $s1, $t6, $t7 #=(Ihigh - Ilow)
li $s2, 255 #=255
div $s1, $s2, $s1 # =[255 / (Ihigh - Ilow)]
mul $t8, $t8, $s1
add $s0, $t8, $zero
sll $t8, $t8, 8
add $s0, $s0, $t8
sll $t8, $t8, 8
add $s0, $s0, $t8
sw $s0, 0($t2)
add $t4, $t4, 1
add $t2, $t2, 4
j loop_coolor_contrastAdjust
fim_loop_coolor_contrastAdjust:
#fim
#end color_contrastAdjust
lw $s0, 0($t9)
lw $s1, 4($t9)
lw $s2, 8($t9)
lw $s3, 12($t9)
lw $s4, 16($t9)
lw $s5, 20($t9)
lw $s6, 24($t9)
lw $s7, 28($t9)
add $sp, $sp, 32
jr $ra
#end contrastAdjust
histogram:
#This histogram will have validity to a 256 color image, such a greyscale one.
#The ideia is to alocate 256 words into stack and each word will have a memory relative position to the first term. This relative
# position will be the color and the word content will be the number of ocurrences. By doing this we save a lot of operations.
# Register usage:
# t0: data info address backup
# t1: pixel iterative address
# t2: stack frame base address
# t3: iteration index
# t4: max number of iterations
# t5: analysed pixel
# t6: retrieved quantity stored
# t7: memory address to store new quantity
add $t0, $a0, $zero #$t0: data info address backup
add $t1, $a1, $zero #$t1: pixel iterative address
add $sp, $sp, -1028
add $t2, $sp, $zero #$t2: stack frame base address
li $t3, 0 #$t3: iteration index
lw $t4, 4($t0)
lw $t5, 8($t0)
mul $t4, $t4, $t5 #$t4: max number of iterations
loop_histogram:
beq $t3, $t4, end_looop_histogram
lb $t5, 0($t1) #$t5: analysed pixel
mul $t5, $t5, 4
add $t7, $t2, $t5 #$t7: memory address to store new quantity
lw $t6, 0($t7) #$t6: retrieved stored quantity
add $t6, $t6, 1
sw $t6, 0($t7)
add $t1, $t1, 4
add $t3, $t3, 1
j loop_histogram
end_looop_histogram:
add $a0, $t2, $zero
add $t9, $ra, $zero
jal printHistogram
add $ra, $t9, $zero
add $sp, $sp, 1028
jr $ra
printHistogram:
# Register usage:
# $t0: stack frame of quantities base address backup
# $t1: referenced color
# $t2: iterative index
# $t3: max number of iterations
# $t4: loaded quantity
add $t0, $a0, $zero #$t0: stack frame of quantities base address backup
li $t1, 0 #$t1: referenced color
li $t2, 0 #$t2: iterative index
li $t3, 256 #$t3: max number of iterations
li $v0, 4
la $a0, strPrintHistogramHeader
syscall
loop_printHistogram:
beq $t1, $t3, end_loop_printHistogram
lw $t4, 0($t0) #$t4: loaded quantity
li $v0, 1
add $a0, $t1, $zero
syscall
li $v0, 4
la $a0, strPrintHistogramHyphen
syscall
li $v0, 1
add $a0, $t4, $zero
syscall
li $v0, 4
la $a0, strHistogramHr
syscall
add $t1, $t1, 1
add $t0, $t0, 4
j loop_printHistogram
end_loop_printHistogram:
#end
jr $ra
#end printHistogram
#end histogram
pixelAverage:
# Register usage:
# t0: data info address backup
# t1: pixel iterative address
# t2: pixel temporary address (for the near pixels)
# t3: linebreak for iterations
# t4: image processable width (since that the borders doesnt count)
# t5: image processable height
# t6: width index
# t7: height index
# t8: new pixel
# t9: temporary pixel
add $t0, $a0, $zero #t0: data info address backup
add $t1, $a1, $zero #t1: pixel iterative address
lw $t4, 4($t0)
sub $t4, $t4, 1 #t4: image processable width
lw $t5, 8($t0)
sub $t5, $t5, 1 #t5: image processable height
mul $t3, $t4, 4 #t3: linebreak for iterations
add $t1, $t1, $t3
add $t1, $t1, 4 #t1: pixel iterative address
add $t2, $t1, $zero #t2: pixel temporary address (for the near pixels)
li $t6, 1
li $t7, 1
add $t8, $ra, $zero
add $a1, $t3, $zero #preparing argument 2 for the seek3x3Average function
loop_pixelAverage:
beq $t6,$t4, refreshPixelAverage
beq $t7,$t5, end_loop_pixelAverage
sub $a0, $t1, $t3
jal seek3x3Average
sw $v0, 0($t1)
add $t1, $t1, 4
add $t6, $t6, 1
j loop_pixelAverage
end_loop_pixelAverage:
#end
add $ra, $t8, $zero
jr $ra
refreshPixelAverage:
li $t6, 1
add $t1, $t1, 8
add $t7, $t7, 1
j loop_pixelAverage
seek3x3Average:
add $sp, $sp, -32
add $t9, $sp, $zero
sw $s0, 0($t9) #some byte
sw $s1, 4($t9) #some byte
sw $s2, 8($t9) #some byte
sw $s3, 12($t9) #some byte
sw $s4, 16($t9) #initial address
sw $s5, 20($t9) #width index
sw $s6, 24($t9) #height index
sw $s7, 28($t9) #Final pixel
li $s5, 0
li $s6, 0
add $a0, $a0, -4
add $s4, $a0, $zero
li $s7, 0
loop_seek3x3Average:
beq $s5, 3, refreshSeek3x3Average
beq $s6, 3, end_loop_seek3x3Average
bne $s5, 2, notCenter_seek3x3Average
bne $s6, 2, notCenter_seek3x3Average
j iterate_seek3x3Average
notCenter_seek3x3Average:
lbu $s0, 0($a0)
div $s0, $s0, 8
lbu $s1, 1($a0)
div $s1, $s1, 8
lbu $s2, 2($a0)
div $s2, $s2, 8
sll $s1, $s1, 8
sll $s2, $s2, 16
add $s7, $s7, $s0
add $s7, $s7, $s1
add $s7, $s7, $s2
#end notCenter_seek3x3Average
iterate_seek3x3Average:
add $a0, $a0, 4
add $s5, $s5, 1
#end iterate_seek3x3Average
j loop_seek3x3Average
end_loop_seek3x3Average:
#end
add $v0, $s7, $zero
lw $s0, 0($t9) #some byte
lw $s1, 4($t9) #some byte
lw $s2, 8($t9) #some byte
lw $s3, 12($t9) #some byte
lw $s4, 16($t9) #initial address
lw $s5, 20($t9) #width index
lw $s6, 24($t9) #height index
lw $s7, 28($t9) #Final pixel
add $sp, $sp, 32
jr $ra
#end seek3x4Average
refreshSeek3x3Average:
li $s5, 0
add $s6, $s6, 1
add $a0, $s4, $a1
j loop_seek3x3Average
#end refreshSeek3x3Average
#end pixelAverage
greyScale:
# Register usage:
# t0: data info address backup
# t1: data address backup
# t2: screen iterative address beggining by 0x10008000
# t3(temporary): height of the image
# t4(temporary): width of the image
# t3: max number of iterations
# t4: iterative index
# t5: image byte
add $t0, $a0, $zero
add $t1, $a1, $zero
la $t2, 0x10008000 #t2: screen start address (iterative)
lw $t3, 4($t0)
lw $t4, 8($t0)
mul $t3, $t3, $t4
li $t4, 1 #t4: iterative index
loop_greyScale:
beq $t3, $t4, end_loop_greyScale
lbu $t5, 0($t2)
mul $t5, $t5, 1140
div $t5, $t5, 10000
lbu $t6, 1($t2)
mul $t6, $t6, 5870
div $t6, $t6, 10000
#sll $t6, $t6, 8
add $t5, $t5, $t6
lbu $t7, 2($t2)
mul $t7, $t7, 2989
div $t7, $t7, 10000
#sll $t7, $t7, 16
add $t5, $t5, $t7
add $t6, $t5, $zero
sll $t6, $t6, 8
add $t7, $t5, $zero
sll $t7, $t7, 16
add $t5,$t5, $t6
add $t5,$t5, $t7
sw $t5, 0($t2)
add $t2, $t2, 4
add $t4, $t4, 1
j loop_greyScale
end_loop_greyScale:
#end
jr $ra
#end greyScale
greenScale:
# Register usage:
# t0: data info address backup
# t1: data address backup
# t2: screen iterative address beggining by 0x10008000
# t3(temporary): height of the image
# t4(temporary): width of the image
# t3: max number of iterations
# t4: iterative index
# t5: image byte
add $t0, $a0, $zero
add $t1, $a1, $zero
la $t2, 0x10008000 #t2: screen start address (iterative)
lw $t3, 4($t0)
lw $t4, 8($t0)
mul $t3, $t3, $t4
li $t4, 1 #t4: iterative index
loop_greenScale:
beq $t3, $t4, end_loop_greenScale
lbu $t5, 0($t2)
mul $t5, $t5, 1140
div $t5, $t5, 10000
lbu $t6, 1($t2)
mul $t6, $t6, 5870
div $t6, $t6, 10000
sll $t6, $t6, 8
add $t5, $t5, $t6
lbu $t7, 2($t2)
mul $t7, $t7, 2989
div $t7, $t7, 10000
sll $t7, $t7, 16
addu $t5, $t5, $t7
sw $t5, 0($t2)
sb $zero, 4($t2)
add $t2, $t2, 4
add $t4, $t4, 1
j loop_greenScale
end_loop_greenScale:
#end
jr $ra
#end greenScale
invertColors:
# Register usage:
# t0: data info address backup
# t1: data address backup
# t2: screen iterative address beggining by 0x10008000
# t3(temporary): height of the image
# t4(temporary): width of the image
# t3: max number of iterations
# t4: iterative index
# t5: image byte
# $t9: 255
add $t0, $a0, $zero
add $t1, $a1, $zero
li $t9, 255
la $t2, 0x10008000 #t2: screen start address (iterative)
lw $t3, 4($t0)
lw $t4, 8($t0)
mul $t3, $t3, $t4
li $t4, 1 #t4: iterative index
loop_invertColors:
beq $t3, $t4, end_loop_invertColors
lb $t5, 0($t2)
sub $t5, $t9, $t5
lb $t6, 1($t2)
sub $t6, $t9, $t6
sll $t6, $t6, 8
add $t5, $t5, $t6
lb $t7, 2($t2)
sub $t7, $t9, $t7
sll $t7, $t7, 16
add $t5, $t5, $t7
sw $t5, 0($t2)
add $t2, $t2, 4
add $t4, $t4, 1
j loop_invertColors
end_loop_invertColors:
#end
jr $ra
#end invertColors
rotate90r:
# Register usage:
# a0: image height or width in pixels(since they are equal doesnt matter)
# a1: start address of the image
#
# t0: line iterative index (n)
# t1: number of matrix lines (N)
# t2: stop condition of the upper for (forNminus2)
# t3: column iterative index (m)
# t4: stop condidition of the lower for (forNminus1)
# t5: byte A(n,m) address
# t6: byte A(m,n) address
# t7: line break address amount
# t8: start address for iterating A(n,n)
# t9: stack for saving registers before swapTerms call
# 0($t9): t0
# 4($t9): t1
# 8($t9): t2
# 12($t9): t3
# 16($t9): t4
# 20($t9): t5
# 24($t9): t6
# 28($t9): t7
# 32($t9): t8
# 36($t9): ra (return address)
li $t0, 0 #t0 will be n
add $t1, $a0, $zero #t1 will be N
add $t1, $t1, 1 #Will correct the zero-indexing of the matrix address
add $t2, $t1, -2 #t2 will be the stop conditon of forNminus2
mul $t7, $a0, 4 #t7 will be \n address amount
add $t8, $a1, $t7 #t8 will be the A(n,n) adress
add $t8, $t8, -4
forNminus2r:
beq $t0, $t2, end_forNminus2r
add $t4, $t0, 1 #t3 will be m
add $t3, $t1, -1 #t4 will be the stop condition of forNminus1
add $t5, $t8, $zero #refresh the address of A(n,m)
add $t6, $t8, $zero #refresh the address of A(m,n)
forNminus1r:
beq $t3, $t4, end_forNminus1r
sub $t5, $t5, 4
add $t6, $t6, $t7
#registerSave:
add $sp, $sp, -40
add $t9, $sp, $zero
sw $t0, 0($t9)
sw $t1, 4($t9)
sw $t2, 8($t9)
sw $t3, 12($t9)
sw $t4, 16($t9)
sw $t5, 20($t9)
sw $t6, 24($t9)
sw $t7, 28($t9)
sw $t8, 32($t9)
sw $ra, 36($t9)
#end registerSave
add $a0, $t5, $zero
add $a1, $t6, $zero
jal swapTerms
#registerRecovery:
lw $t0, 0($t9)
lw $t1, 4($t9)
lw $t2, 8($t9)
lw $t3, 12($t9)
lw $t4, 16($t9)
lw $t5, 20($t9)
lw $t6, 24($t9)
lw $t7, 28($t9)
lw $t8, 32($t9)
lw $ra, 36($t9)
add $sp, $sp, 40
#end registerRecovery
sub $t3, $t3, 1
j forNminus1r
end_forNminus1r:
#end
add $t8, $t8, $t7
sub $t8, $t8, 4
add $t0, $t0, 1
j forNminus2r
end_forNminus2r:
#end
jr $ra
#end rotate90r
rotate90l:
# Register usage:
# a0: image height or width in pixels(since they are equal doesnt matter)
# a1: start address of the image
#
# t0: line iterative index (n)
# t1: number of matrix lines (N)
# t2: stop condition of the upper for (forNminus2)
# t3: column iterative index (m)
# t4: stop condidition of the lower for (forNminus1)
# t5: byte A(n,m) address
# t6: byte A(m,n) address
# t7: line break address amount
# t8: start address for iterating A(n,n)
# t9: stack for saving registers before swapTerms call
# 0($t9): t0
# 4($t9): t1
# 8($t9): t2
# 12($t9): t3
# 16($t9): t4
# 20($t9): t5
# 24($t9): t6
# 28($t9): t7
# 32($t9): t8
# 36($t9): ra (return address)
#for n = 0 to N - 2
# for m = n + 1 to N - 1
# swap A(n,m) with A(m,n)
li $t0, 0 #t0 will be n
add $t1, $a0, $zero #t1 will be N
add $t1, $t1, 1 #Will correct the zero-indexing of the matrix address
add $t2, $t1, -2 #t2 will be the stop conditon of forNminus2
mul $t7, $a0, 4 #t7 will be \n address amount
add $t8, $a1, $zero #t8 will be the A(n,n) adress
forNminus2:
beq $t0, $t2, end_forNminus2
add $t3, $t0, 1 #t3 will be m