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
| #----------------------------------------------------------
#Program description: rotate a fixed-size square pictures by 90 degree, program should read and output a .bmp file using 1bpp format
#Date:10/05/2012
#Author:Oussama Sabri
#----------------------------------------------------------
#Data section
.data
path1: .asciiz "C:\Users\osabri\Desktop\ecoar_project1_S12\pictin.bmp"
path2: .asciiz "C:\Users\osabri\Desktop\ecoar_project1_S12\pictout.bmp"
buf: .space 574
bufout: .space 512
.text
main: #code section
li $v0, 13 #open file
la $a0, path1 #load file address
li $a1, 0 #drapeaux
li $a2, 0
syscall #fichier desc
move $t1, $v0 #enregistrer fichier desc
move $a0, $t1
li $v0, 14 #read from file
la $a1, buf #place the starting address of buffer in $a1
li $a2, 574 #nombre maximum de bites
syscall #appeller OS pour lire
li $v0, 16 #close file
move $a0, $t1 #restaurer fichier desc
syscall
#----------------------------------------------------------
li $s3 0 #readout counter
li $s0 62 #counter to read from 62
li $s1 128 #mask to read
li $t1 128 #mask to save
li $t2 512 #start
li $t4 0 #horizontal loop
horizontal:
li $t2 512
add $t2 $t2 $t4 #s = 128 + d
vertical:
sub $t2 8 #s = s - 8 -> s = 124,120...
#----------------------------------------------------------
add $s3 1 #readout++
lb $s6 buf($s0) #readout
and $s7 $s6 $s1 #get bit
srl $s1 $s1 1
bgt $s1 0 readnext
li $s1 128 #if (s1 <= 0) {s1 = 128, s0++}
add $s0 1
readnext:
#----------------------------------------------------------
lb $t7 bufout($t2)
beq $s7 0 nochange
add $t7 $t7 $t1 #add pixel
nochange:
sb $t7 bufout($t2) #put new value
writenext:
#----------------------------------------------------------
bge $s3 4096 end #End
bge $t2 8 vertical # t2>=4 -> -4 on the loop start
#t2 < 4 -> move mask
srl $t1 $t1 1
bgt $t1 0 horizontal #continue
#maska == 0
li $t1 128
add $t4 1 #move++
j horizontal #go to horizontal
end:
la $a0, path2
li $a2, 0666
li $a1, 0x101
li $v0, 13 #open file
syscall
move $t2, $v0
move $a0, $t2
li $v0, 15 #write to file
la $a1, buf
li $a2, 62
syscall
move $a0, $t2
li $v0, 15
la $a1, bufout
li $a2, 512
syscall
li $v0, 16 #close file
move $a0, $t2
syscall
la $v0 10 #system call code for exit
syscall |
Partager