mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 18:23:06 +02:00
Adding project files
This commit is contained in:
commit
5cc0124d73
BIN
ECOAR/Puzzle/Mars4_5.jar
Executable file
BIN
ECOAR/Puzzle/Mars4_5.jar
Executable file
Binary file not shown.
BIN
ECOAR/Puzzle/dest.bmp
Executable file
BIN
ECOAR/Puzzle/dest.bmp
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/Puzzle/naru2.bmp
Executable file
BIN
ECOAR/Puzzle/naru2.bmp
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
406
ECOAR/Puzzle/puzzle.asm
Executable file
406
ECOAR/Puzzle/puzzle.asm
Executable file
@ -0,0 +1,406 @@
|
|||||||
|
#only 24-bits 320x240 pixels BMP files are supported
|
||||||
|
# 24 * 320 * 240 = 1843200 bits = 1843200 / 8 bytes = 230400 bytes
|
||||||
|
# let's round it to 240000 for a good measure
|
||||||
|
.eqv BMP_FILE_SIZE 230454
|
||||||
|
.eqv BYTES_PER_ROW 960
|
||||||
|
|
||||||
|
.data
|
||||||
|
.align 4
|
||||||
|
res: .space 2
|
||||||
|
image: .space BMP_FILE_SIZE
|
||||||
|
start_message_vertical: .asciiz "\nEnter number of vertical divisions:\n" # .asciiz stores the string
|
||||||
|
end_message_vertical: .asciiz "You entered this many vertical divisions: "
|
||||||
|
start_message_horizontal: .asciiz "\nEnter number of horizontal divisions:\n"
|
||||||
|
end_message_horizontal : .asciiz "You entered this many horizontal divisions: "
|
||||||
|
start_message: .asciiz "Enter number of vertical and horizontal divisions:\n"
|
||||||
|
buffer: .space 1024
|
||||||
|
HEIGHT: .word 240
|
||||||
|
WIDTH: .word 320
|
||||||
|
newline: .asciiz "\n"
|
||||||
|
pieces: .word
|
||||||
|
input_file_name: .asciiz "source.bmp" # name of input file as choosen in the project instruction
|
||||||
|
output_file_name: .asciiz "dest.bmp" # name of output file as choosen in the project instruction
|
||||||
|
|
||||||
|
.text
|
||||||
|
|
||||||
|
_main:
|
||||||
|
jal user_input_horizontal_division # puts number of horizontal divisions to $s5
|
||||||
|
jal user_input_vertical_division # puts number of vertical divisions to $s4
|
||||||
|
jal calculate_number_of_pieces # puts number of pieces to $s3
|
||||||
|
jal random_number
|
||||||
|
jal calculate_piece_WIDTH # calculates the WIDTH of a single piece based on number of vertical divisons
|
||||||
|
jal calculate_piece_HEIGHT # calculates the WIDTH of a single piece based on number of horizontal divisons
|
||||||
|
jal read_bmp
|
||||||
|
|
||||||
|
li $a0, 8
|
||||||
|
jal calculate_piece_position_x
|
||||||
|
li $a0, 8
|
||||||
|
jal calculate_piece_position_y
|
||||||
|
li $a0, 9
|
||||||
|
jal calculate_piece_position_y
|
||||||
|
li $a0, 5
|
||||||
|
jal calculate_piece_position_y
|
||||||
|
li $a0, 2
|
||||||
|
jal calculate_piece_position_y
|
||||||
|
li $a0, 10
|
||||||
|
jal calculate_piece_position_y
|
||||||
|
|
||||||
|
#put red pixel in bottom left corner
|
||||||
|
li $a0, 0 #x
|
||||||
|
li $a1, 0 #y
|
||||||
|
li $a2, 0x00FF0000 #color - 00RRGGBB
|
||||||
|
jal put_pixel
|
||||||
|
|
||||||
|
#get pixel from x y
|
||||||
|
li $a0, 0 #x
|
||||||
|
li $a1, 0 #y
|
||||||
|
jal get_pixel_v0
|
||||||
|
#get pixel from x y
|
||||||
|
li $a0, 0 #x
|
||||||
|
li $a1, 5 #y
|
||||||
|
jal get_pixel_v1
|
||||||
|
|
||||||
|
#put pixel that we got from the previous get pixel to x y position
|
||||||
|
li $a0, 0 #x
|
||||||
|
li $a1, 1 #y
|
||||||
|
move $a2, $v0
|
||||||
|
jal put_pixel
|
||||||
|
|
||||||
|
#put pixel that we got from the previous get pixel to x y position
|
||||||
|
li $a0, 0 #x
|
||||||
|
li $a1, 2 #y
|
||||||
|
move $a2, $v1
|
||||||
|
jal put_pixel
|
||||||
|
|
||||||
|
jal save_bmp
|
||||||
|
jal end_program
|
||||||
|
|
||||||
|
.macro print(%text)
|
||||||
|
la $a0, %text
|
||||||
|
li $v0, 4
|
||||||
|
syscall
|
||||||
|
.end_macro
|
||||||
|
|
||||||
|
.macro print_int(%num)
|
||||||
|
li $v0, 1 # If you want to print the integer the code is 1
|
||||||
|
move $a0, %num # move the integer stored in %num to $a0
|
||||||
|
syscall
|
||||||
|
.end_macro
|
||||||
|
|
||||||
|
.macro println()
|
||||||
|
la $a0, newline # New line string stored here
|
||||||
|
li $v0, 4
|
||||||
|
syscall
|
||||||
|
.end_macro
|
||||||
|
|
||||||
|
|
||||||
|
calculate_piece_position_x: # piece value is taken from $a0
|
||||||
|
div $a0, $s4 # number of vertical divisons is stored in $s4
|
||||||
|
mfhi $a1
|
||||||
|
beq $a1, 0, piece_position_x_mod_zero
|
||||||
|
sub $a1, $a1, 1
|
||||||
|
println()
|
||||||
|
print_int($a1)
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
piece_position_x_mod_zero:
|
||||||
|
li $a2, 0
|
||||||
|
add $a2, $a2, $s5
|
||||||
|
println()
|
||||||
|
print_int($a2)
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
|
||||||
|
calculate_piece_position_y: #piece value is taken from $a0
|
||||||
|
div $a0, $s4
|
||||||
|
mfhi $a1
|
||||||
|
beq $a1, 0, piece_position_y_mod_zero
|
||||||
|
div $a2, $a0, $s4
|
||||||
|
move $t0, $s4
|
||||||
|
sub $a2, $t0, $a2
|
||||||
|
println()
|
||||||
|
print_int($a2)
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
|
||||||
|
piece_position_y_mod_zero:
|
||||||
|
div $a2, $a0, $s4
|
||||||
|
li $t0, 0
|
||||||
|
add $t0, $s4, 1
|
||||||
|
sub $a2, $t0, $a2
|
||||||
|
println()
|
||||||
|
print_int($a2)
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
calculate_number_of_pieces:
|
||||||
|
mul $s3, $s4, $s5
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
random_number:
|
||||||
|
move $a1, $s3 #Here you set $a1 to the max bound.
|
||||||
|
li $v0, 42 #generates the random number.
|
||||||
|
syscall
|
||||||
|
#add $a0, $a0, 100 #Here you add the lowest bound
|
||||||
|
#li $v0, 1 #1 print integer
|
||||||
|
syscall
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
close_file:
|
||||||
|
li $v0, 16
|
||||||
|
move $a0, $s6
|
||||||
|
syscall
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
calculate_piece_WIDTH:
|
||||||
|
lw $a0, HEIGHT
|
||||||
|
div $s1, $a0, $s4 # number of vertical divisons is kept in $s1
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
calculate_piece_HEIGHT:
|
||||||
|
lw $a0, WIDTH
|
||||||
|
div $s2, $a0, $s5 # number of vertical divisons is kept in $s2
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
display_start_message:
|
||||||
|
print(start_message)
|
||||||
|
|
||||||
|
|
||||||
|
user_input_vertical_division: # puts number of vertical divisions to $s4
|
||||||
|
print(start_message_vertical)
|
||||||
|
li $v0, 5 # we want to get the integer from the keyboard
|
||||||
|
syscall # this will allow us to enter the number which will be stored in $v0
|
||||||
|
# Store the result in $t0
|
||||||
|
move $s4, $v0 # $t0 = $v0
|
||||||
|
print(end_message_vertical)
|
||||||
|
print_int($s4)
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
enter_int:
|
||||||
|
li $v0, 5 # we want to get the integer from the keyboard
|
||||||
|
syscall # this will allow us to enter the number which will be stored in $v0
|
||||||
|
# Store the result in $t0
|
||||||
|
move $t0, $v0 # $t0 = $v0
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
user_input_horizontal_division: # puts number of vertical divisions to $s5
|
||||||
|
print(start_message_horizontal)
|
||||||
|
li $v0, 5 # we want to get the integer from the keyboard
|
||||||
|
syscall # this will allow us to enter the number which will be stored in $v0
|
||||||
|
# Store the result in $t0
|
||||||
|
move $s5, $v0 # $t0 = $v0
|
||||||
|
print(end_message_horizontal)
|
||||||
|
print_int($s5)
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
calculate_picture_area:
|
||||||
|
lw $t0, HEIGHT
|
||||||
|
lw $t1, WIDTH
|
||||||
|
mul $t2, $t0, $t1
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
read_bmp:
|
||||||
|
#description:
|
||||||
|
# reads the contents of a bmp file into memory
|
||||||
|
#arguments:
|
||||||
|
# none
|
||||||
|
#return value: none
|
||||||
|
sub $sp, $sp, 4 #push $ra to the stack
|
||||||
|
sw $ra,($sp)
|
||||||
|
sub $sp, $sp, 4 #push $s1
|
||||||
|
sw $s1, ($sp)
|
||||||
|
#open file
|
||||||
|
li $v0, 13
|
||||||
|
la $a0, input_file_name #file name
|
||||||
|
li $a1, 0 #flags: 0-read file
|
||||||
|
li $a2, 0 #mode: ignored
|
||||||
|
syscall
|
||||||
|
move $s1, $v0 # save the file descriptor
|
||||||
|
|
||||||
|
#check for errors - if the file was opened
|
||||||
|
#...
|
||||||
|
|
||||||
|
#read file
|
||||||
|
li $v0, 14
|
||||||
|
move $a0, $s1
|
||||||
|
la $a1, image
|
||||||
|
li $a2, BMP_FILE_SIZE
|
||||||
|
syscall
|
||||||
|
|
||||||
|
#close file
|
||||||
|
li $v0, 16
|
||||||
|
move $a0, $s1
|
||||||
|
syscall
|
||||||
|
|
||||||
|
lw $s1, ($sp) #restore (pop) $s1
|
||||||
|
add $sp, $sp, 4
|
||||||
|
lw $ra, ($sp) #restore (pop) $ra
|
||||||
|
add $sp, $sp, 4
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
put_pixel:
|
||||||
|
#description:
|
||||||
|
# sets the color of specified pixel
|
||||||
|
#arguments:
|
||||||
|
# $a0 - x coordinate
|
||||||
|
# $a1 - y coordinate - (0,0) - bottom left corner
|
||||||
|
# $a2 - 0RGB - pixel color
|
||||||
|
#return value: none
|
||||||
|
|
||||||
|
sub $sp, $sp, 4 #push $ra to the stack
|
||||||
|
sw $ra,($sp)
|
||||||
|
|
||||||
|
la $t1, image + 10 #adress of file offset to pixel array
|
||||||
|
lw $t2, ($t1) #file offset to pixel array in $t2
|
||||||
|
la $t1, image #adress of bitmap
|
||||||
|
add $t2, $t1, $t2 #adress of pixel array in $t2
|
||||||
|
|
||||||
|
#pixel address calculation
|
||||||
|
mul $t1, $a1, BYTES_PER_ROW #t1= y*BYTES_PER_ROW
|
||||||
|
move $t3, $a0
|
||||||
|
sll $a0, $a0, 1
|
||||||
|
add $t3, $t3, $a0 #$t3= 3*x
|
||||||
|
add $t1, $t1, $t3 #$t1 = 3x + y*BYTES_PER_ROW
|
||||||
|
add $t2, $t2, $t1 #pixel address
|
||||||
|
|
||||||
|
#set new color
|
||||||
|
sb $a2,($t2) #store B
|
||||||
|
srl $a2,$a2,8
|
||||||
|
sb $a2,1($t2) #store G
|
||||||
|
srl $a2,$a2,8
|
||||||
|
sb $a2,2($t2) #store R
|
||||||
|
|
||||||
|
lw $ra, ($sp) #restore (pop) $ra
|
||||||
|
add $sp, $sp, 4
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
|
||||||
|
get_pixel_v0:
|
||||||
|
#description:
|
||||||
|
# returns color of specified pixel
|
||||||
|
#arguments:
|
||||||
|
# $a0 - x coordinate
|
||||||
|
# $a1 - y coordinate - (0,0) - bottom left corner
|
||||||
|
#return value:
|
||||||
|
# $v0 - 0RGB - pixel color
|
||||||
|
|
||||||
|
sub $sp, $sp, 4 #push $ra to the stack
|
||||||
|
sw $ra,($sp)
|
||||||
|
|
||||||
|
la $t1, image + 10 #adress of file offset to pixel array
|
||||||
|
lw $t2, ($t1) #file offset to pixel array in $t2
|
||||||
|
la $t1, image #adress of bitmap
|
||||||
|
add $t2, $t1, $t2 #adress of pixel array in $t2
|
||||||
|
|
||||||
|
#pixel address calculation
|
||||||
|
mul $t1, $a1, BYTES_PER_ROW #t1= y*BYTES_PER_ROW
|
||||||
|
move $t3, $a0
|
||||||
|
sll $a0, $a0, 1
|
||||||
|
add $t3, $t3, $a0 #$t3= 3*x
|
||||||
|
add $t1, $t1, $t3 #$t1 = 3x + y*BYTES_PER_ROW
|
||||||
|
add $t2, $t2, $t1 #pixel address
|
||||||
|
|
||||||
|
#get color
|
||||||
|
lbu $v0,($t2) #load B
|
||||||
|
lbu $t1,1($t2) #load G
|
||||||
|
sll $t1,$t1,8
|
||||||
|
or $v0, $v0, $t1
|
||||||
|
lbu $t1,2($t2) #load R
|
||||||
|
sll $t1,$t1,16
|
||||||
|
or $v0, $v0, $t1
|
||||||
|
|
||||||
|
lw $ra, ($sp) #restore (pop) $ra
|
||||||
|
add $sp, $sp, 4
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
get_pixel_v1:
|
||||||
|
#description:
|
||||||
|
# returns color of specified pixel
|
||||||
|
#arguments:
|
||||||
|
# $a0 - x coordinate
|
||||||
|
# $a1 - y coordinate - (0,0) - bottom left corner
|
||||||
|
#return value:
|
||||||
|
# $v1 - 0RGB - pixel color
|
||||||
|
|
||||||
|
sub $sp, $sp, 4 #push $ra to the stack
|
||||||
|
sw $ra,($sp)
|
||||||
|
|
||||||
|
la $t1, image + 10 #adress of file offset to pixel array
|
||||||
|
lw $t2, ($t1) #file offset to pixel array in $t2
|
||||||
|
la $t1, image #adress of bitmap
|
||||||
|
add $t2, $t1, $t2 #adress of pixel array in $t2
|
||||||
|
|
||||||
|
#pixel address calculation
|
||||||
|
mul $t1, $a1, BYTES_PER_ROW #t1= y*BYTES_PER_ROW
|
||||||
|
move $t3, $a0
|
||||||
|
sll $a0, $a0, 1
|
||||||
|
add $t3, $t3, $a0 #$t3= 3*x
|
||||||
|
add $t1, $t1, $t3 #$t1 = 3x + y*BYTES_PER_ROW
|
||||||
|
add $t2, $t2, $t1 #pixel address
|
||||||
|
|
||||||
|
#get color
|
||||||
|
lbu $v1,($t2) #load B
|
||||||
|
lbu $t1,1($t2) #load G
|
||||||
|
sll $t1,$t1,8
|
||||||
|
or $v1 $v1, $t1
|
||||||
|
lbu $t1,2($t2) #load R
|
||||||
|
sll $t1,$t1,16
|
||||||
|
or $v1, $v1, $t1
|
||||||
|
|
||||||
|
lw $ra, ($sp) #restore (pop) $ra
|
||||||
|
add $sp, $sp, 4
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
save_bmp:
|
||||||
|
#description:
|
||||||
|
# saves bmp file stored in memory to a file
|
||||||
|
#arguments:
|
||||||
|
# none
|
||||||
|
#return value: none
|
||||||
|
sub $sp, $sp, 4 #push $ra to the stack
|
||||||
|
sw $ra,($sp)
|
||||||
|
sub $sp, $sp, 4 #push $s1
|
||||||
|
sw $s1, ($sp)
|
||||||
|
#open file
|
||||||
|
li $v0, 13
|
||||||
|
la $a0, output_file_name #file name
|
||||||
|
li $a1, 1 #flags: 1-write file
|
||||||
|
li $a2, 0 #mode: ignored
|
||||||
|
syscall
|
||||||
|
move $s1, $v0 # save the file descriptor
|
||||||
|
|
||||||
|
#check for errors - if the file was opened
|
||||||
|
#...
|
||||||
|
|
||||||
|
#save file
|
||||||
|
li $v0, 15
|
||||||
|
move $a0, $s1
|
||||||
|
la $a1, image
|
||||||
|
li $a2, BMP_FILE_SIZE
|
||||||
|
syscall
|
||||||
|
|
||||||
|
#close file
|
||||||
|
li $v0, 16
|
||||||
|
move $a0, $s1
|
||||||
|
syscall
|
||||||
|
|
||||||
|
lw $s1, ($sp) #restore (pop) $s1
|
||||||
|
add $sp, $sp, 4
|
||||||
|
lw $ra, ($sp) #restore (pop) $ra
|
||||||
|
add $sp, $sp, 4
|
||||||
|
jr $ra
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end_program:
|
||||||
|
li $v0, 10
|
||||||
|
syscall
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BIN
ECOAR/Puzzle/source.bmp
Executable file
BIN
ECOAR/Puzzle/source.bmp
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
26
ECOAR/x86/C/asm_part.asm
Executable file
26
ECOAR/x86/C/asm_part.asm
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
section .text
|
||||||
|
global hello_world ;must be declared for linker (ld)
|
||||||
|
|
||||||
|
hello_world: ;tells linker entry point
|
||||||
|
|
||||||
|
push ebp
|
||||||
|
mov ebp,esp
|
||||||
|
push ebx
|
||||||
|
|
||||||
|
mov edx,len ;message length
|
||||||
|
mov ecx,msg ;message to write
|
||||||
|
mov ebx,1 ;file descriptor (stdout)
|
||||||
|
mov eax,4 ;system call number (sys_write)
|
||||||
|
int 0x80 ;call kernel
|
||||||
|
|
||||||
|
pop ebx
|
||||||
|
mov esp, ebp
|
||||||
|
pop ebp
|
||||||
|
ret
|
||||||
|
|
||||||
|
;mov eax,1 ;system call number (sys_exit)
|
||||||
|
;int 0x80 ;call kernel
|
||||||
|
|
||||||
|
section .data
|
||||||
|
msg db 'Hello, world!', 0xa ;string to be printed
|
||||||
|
len equ $ - msg ;length of the string
|
||||||
27
ECOAR/x86/C/asm_part.lst
Executable file
27
ECOAR/x86/C/asm_part.lst
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
1 section .text
|
||||||
|
2 global hello_world ;must be declared for linker (ld)
|
||||||
|
3
|
||||||
|
4 hello_world: ;tells linker entry point
|
||||||
|
5
|
||||||
|
6 00000000 55 push ebp
|
||||||
|
7 00000001 89E5 mov ebp,esp
|
||||||
|
8 00000003 53 push ebx
|
||||||
|
9
|
||||||
|
10 00000004 BA0E000000 mov edx,len ;message length
|
||||||
|
11 00000009 B9[00000000] mov ecx,msg ;message to write
|
||||||
|
12 0000000E BB01000000 mov ebx,1 ;file descriptor (stdout)
|
||||||
|
13 00000013 B804000000 mov eax,4 ;system call number (sys_write)
|
||||||
|
14 00000018 CD80 int 0x80 ;call kernel
|
||||||
|
15
|
||||||
|
16 0000001A 5B pop ebx
|
||||||
|
17 0000001B 89EC mov esp, ebp
|
||||||
|
18 0000001D 5D pop ebp
|
||||||
|
19 0000001E C3 ret
|
||||||
|
20
|
||||||
|
21 ;mov eax,1 ;system call number (sys_exit)
|
||||||
|
22 ;int 0x80 ;call kernel
|
||||||
|
23
|
||||||
|
24 section .data
|
||||||
|
25 00000000 48656C6C6F2C20776F- msg db 'Hello, world!', 0xa ;string to be printed
|
||||||
|
25 00000009 726C64210A
|
||||||
|
26 len equ $ - msg ;length of the string
|
||||||
BIN
ECOAR/x86/C/asm_part.o
Executable file
BIN
ECOAR/x86/C/asm_part.o
Executable file
Binary file not shown.
BIN
ECOAR/x86/C/dest.bmp
Executable file
BIN
ECOAR/x86/C/dest.bmp
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
14
ECOAR/x86/C/makefile
Executable file
14
ECOAR/x86/C/makefile
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
CC=gcc
|
||||||
|
ASMBIN=nasm
|
||||||
|
|
||||||
|
all : asm cc link
|
||||||
|
asm :
|
||||||
|
$(ASMBIN) -o asm_part.o -f elf -l asm_part.lst asm_part.asm
|
||||||
|
cc :
|
||||||
|
$(CC) -m32 -c -g -O0 puzzle.c -no-pie
|
||||||
|
link :
|
||||||
|
$(CC) -m32 -o puzzle_test.out puzzle.o asm_part.o -no-pie
|
||||||
|
clean :
|
||||||
|
rm *.o
|
||||||
|
rm setcol_test
|
||||||
|
rm asm_part.lst
|
||||||
BIN
ECOAR/x86/C/opis projektow.pdf
Executable file
BIN
ECOAR/x86/C/opis projektow.pdf
Executable file
Binary file not shown.
BIN
ECOAR/x86/C/pictures/source.bmp
Executable file
BIN
ECOAR/x86/C/pictures/source.bmp
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
398
ECOAR/x86/C/puzzle.c
Executable file
398
ECOAR/x86/C/puzzle.c
Executable file
@ -0,0 +1,398 @@
|
|||||||
|
// ECOAR x86 PUZZLE Project Krzysztof Rudnicki, 307585
|
||||||
|
#include <stdio.h> // fopen(); fread(); fwrite(); fclose()
|
||||||
|
#include <stdlib.h> // printf(); srand();
|
||||||
|
#include <memory.h> // malloc(); free();
|
||||||
|
#include <time.h> // time();
|
||||||
|
|
||||||
|
const int BMP_HEADER_SIZE = 54;
|
||||||
|
// as per: https://www.daubnet.com/en/file-format-bmp
|
||||||
|
const int BMP_SIGNATURE_0x = 0x4D42;
|
||||||
|
// as per: https://www.daubnet.com/en/file-format-bmp
|
||||||
|
const int NUMBER_OF_HEADERS = 1; // There is only one header in BMP file
|
||||||
|
const int BYTE_PER_PIXEL = 24; // as per project description of the bmp file
|
||||||
|
const int DESIRED_COMPRESSION_VALUE = 0;
|
||||||
|
// as per project description of the bmp file
|
||||||
|
const int CANNOT_OPEN_FILE_FOR_WRITING = -1;
|
||||||
|
const int CANNOT_WRITE_HEADER_OR_IMAGE = -2;
|
||||||
|
const int BYTES_FOR_SINGLE_PIXEL = 3; // R byte + G byte + B byte
|
||||||
|
const int WRONG_BMP_HEADER_SIZE = 1;
|
||||||
|
const int ERROR_READING_SOURCE_FILE = 2;
|
||||||
|
|
||||||
|
const char ENTER_VERTICAL_DIVISON_MESSAGE[]
|
||||||
|
= "Enter number of vertical divisons: ";
|
||||||
|
|
||||||
|
const char ENTER_HORIZONTAL_DIVISON_MESSAGE[]
|
||||||
|
= "Enter number of horizontal divisons: ";
|
||||||
|
|
||||||
|
const char WRONG_BMP_HEADER_SIZE_MESSAGE[]
|
||||||
|
= "Check compilation options so as bmpHeaderInfo struct size is 54 bytes.\n";
|
||||||
|
|
||||||
|
const char READ_AND_BINARY_MODE[] = "rb"; // open file to read and binary mode
|
||||||
|
const char WRITE_AND_BINARY_MODE[] = "wb"; // open file to write and binary mode
|
||||||
|
const char SOURCE_IMAGE_NAME[] = "source.bmp"; // as per project description
|
||||||
|
const char DESTINATION_IMAGE_NAME[] = "dest.bmp"; // as per project description
|
||||||
|
const char ERROR_READING_SOURCE_FILE_MESSAGE[]
|
||||||
|
= "Error reading source file (probably).\n";
|
||||||
|
|
||||||
|
// "Specifies the packing alignment for structure, union, and class members."
|
||||||
|
// something like .align in MIPS?
|
||||||
|
// https://docs.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-160
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
/* push - pushed to stack, n = 1
|
||||||
|
n - (Optional) Specifies the value, in bytes, to be used for packing.
|
||||||
|
If the compiler option /Zp isn't set for the module,
|
||||||
|
the default value for n is 8. Valid values are 1, 2, 4, 8, and 16.
|
||||||
|
The alignment of a member is on a boundary that's either a
|
||||||
|
multiple of n, or a multiple of the size of the member,
|
||||||
|
whichever is smaller. */
|
||||||
|
// We pack it to "1" to get exactly 54 bytes for bmpHeaderInfo structure
|
||||||
|
// Changing it to "8" gives us an error, changing it to "2" does not
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned short bytesImageType; // 0x4D42 = "BMP" in Ascii, not used
|
||||||
|
unsigned long bytesFileSize; // file size in bytes, not used
|
||||||
|
unsigned short bfReservedOne; // reserved bytes from bmp file
|
||||||
|
unsigned short bfReservedTwo; // reserved bytes from bmp file
|
||||||
|
unsigned long bytesPixelDataOffset; // offset of pixel data, not used
|
||||||
|
unsigned long bytesHeaderSize;
|
||||||
|
// header size (bitmap info size), not used
|
||||||
|
long bytesImageWidth; // image width, USED
|
||||||
|
long bytesImageHeight; // image height, USED
|
||||||
|
short bytesBitmapPlanes; // bitmap planes (== 1) USED
|
||||||
|
short bytesPixelBitCount;
|
||||||
|
// bit count of a pixel (== 24) (24 from project description), USED
|
||||||
|
unsigned long bytesImageCompression;
|
||||||
|
// should be 0 (no compression), USED
|
||||||
|
unsigned long bytesImageSize; // image size (not file size!), USED
|
||||||
|
long bytesHorizontalResolution; // horizontal resolution, not used
|
||||||
|
long bytesVerticalResolution; // vertical resolution, not used
|
||||||
|
unsigned long bytesColorsUsed;
|
||||||
|
// not important for RGB images, not used
|
||||||
|
unsigned long bytesColorsImportant;
|
||||||
|
// not important for RGB images, not used
|
||||||
|
} bmpHeaderInfo;
|
||||||
|
// Struct containing info from header of a RGB type BMP file
|
||||||
|
|
||||||
|
#pragma pack(pop)
|
||||||
|
// stack popped
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned int imageWidth, imageHeight; // same as in bmpHeaderInfo
|
||||||
|
unsigned int bytesPerRow;
|
||||||
|
// Bytes per row, important in MIPS, important here
|
||||||
|
unsigned char* pImg;
|
||||||
|
// pImg is a pointer to the begining of pixels data of the picture
|
||||||
|
bmpHeaderInfo *pHeaderInfo; // pointer to info from header
|
||||||
|
} imageInfo; // Stores info about image
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int vertical;
|
||||||
|
int horizontal;
|
||||||
|
} divisions;
|
||||||
|
|
||||||
|
// If we want to write something to imageInfo struct first we need to empty it
|
||||||
|
imageInfo* allocateSpaceForImageInfo()
|
||||||
|
{
|
||||||
|
// we allocate as much space as this struct needs
|
||||||
|
imageInfo* emptyImageInfo = malloc(sizeof(imageInfo));
|
||||||
|
// Then in this if we basically set starting values for everything we care about
|
||||||
|
if (emptyImageInfo != NULL)
|
||||||
|
{
|
||||||
|
emptyImageInfo->imageWidth = 0;
|
||||||
|
emptyImageInfo->imageHeight = 0;
|
||||||
|
emptyImageInfo->bytesPerRow = 0;
|
||||||
|
emptyImageInfo->pImg = NULL;
|
||||||
|
emptyImageInfo->pHeaderInfo = NULL;
|
||||||
|
}
|
||||||
|
return emptyImageInfo; // Then we retun the struct that we will use
|
||||||
|
}
|
||||||
|
|
||||||
|
void* freeImageInfo(imageInfo* toFree)
|
||||||
|
{
|
||||||
|
if (toFree != NULL) // If image info is already empty no need to free it
|
||||||
|
{
|
||||||
|
if (toFree->pImg != NULL) free(toFree->pImg);
|
||||||
|
// pImg is an char* so we need to free it extra
|
||||||
|
if (toFree->pHeaderInfo != NULL) free(toFree->pHeaderInfo);
|
||||||
|
// pHeaderInfo is a struct so we need to free it extra
|
||||||
|
free(toFree); // Finally we can free the rest of the struct
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
// we return void* since function readBMP calling freeImageInfo returns a
|
||||||
|
// pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
// We use pFile to read/write to file and struct containing imageInfo in our
|
||||||
|
// program, we have to free memory after using these two
|
||||||
|
void* freeResources(FILE* pFile, imageInfo* toFree)
|
||||||
|
{
|
||||||
|
if (pFile != NULL) fclose(pFile); // Close file if it isn't already closed
|
||||||
|
return freeImageInfo(toFree);
|
||||||
|
}
|
||||||
|
|
||||||
|
imageInfo* readBMP(const char* fileName)
|
||||||
|
{
|
||||||
|
imageInfo* pInfo = 0;
|
||||||
|
/* https://stackoverflow.com/q/48288191
|
||||||
|
Assignment of the constant 0 to a pointer will produce a null pointer
|
||||||
|
distinguishable from a pointer to any object. */
|
||||||
|
FILE* bmpFile = 0;
|
||||||
|
|
||||||
|
// allocateSpaceForImageInfo returns NULL if something went bad
|
||||||
|
pInfo = allocateSpaceForImageInfo();
|
||||||
|
if (pInfo == NULL) return NULL;
|
||||||
|
|
||||||
|
|
||||||
|
// if fopen returns NULL then something bad happened
|
||||||
|
bmpFile = fopen(fileName, READ_AND_BINARY_MODE);
|
||||||
|
// cannot open file
|
||||||
|
if (bmpFile == NULL) return freeResources(bmpFile, pInfo);
|
||||||
|
|
||||||
|
/* 1. if malloc didn't allocate any memory then something bad happened
|
||||||
|
fread arguments: buffer to which we will save data that we read
|
||||||
|
size of single data element in bytes
|
||||||
|
number of elements that we will read
|
||||||
|
stream on which this operation will be done
|
||||||
|
We will save data to pHeaderInfo so that's our buffer
|
||||||
|
We will get as much data as there is in bmpHeader
|
||||||
|
There is just one header so we will read just from one header
|
||||||
|
We will read all of that from bmp file
|
||||||
|
it returns number of correctly read values, our desired return value is
|
||||||
|
1 so if it returns any other then there was a mistake
|
||||||
|
NUMBER_OF_HEADERS = 1 */
|
||||||
|
pInfo->pHeaderInfo = malloc(sizeof(bmpHeaderInfo));
|
||||||
|
size_t returnedElements = fread((void*)pInfo->pHeaderInfo,
|
||||||
|
sizeof(bmpHeaderInfo),
|
||||||
|
NUMBER_OF_HEADERS,
|
||||||
|
bmpFile);
|
||||||
|
|
||||||
|
if (pInfo->pHeaderInfo == NULL || returnedElements != NUMBER_OF_HEADERS)
|
||||||
|
{
|
||||||
|
return freeResources(bmpFile, pInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We check if image type is different than BMP
|
||||||
|
We check if bitmap planes are different than 1
|
||||||
|
we check if number of bits in one pixels is differnt than 24
|
||||||
|
we check if there is any image compresssion
|
||||||
|
those are the project assumptions if any of them are broken then there
|
||||||
|
was a mistake
|
||||||
|
BMP_SIGNATURE_0x = 0x4D42
|
||||||
|
BYTE_PER_PIXEL = 24
|
||||||
|
DESIRED_COMPRESSION_VALUE = 0 */
|
||||||
|
if( pInfo->pHeaderInfo->bytesImageType != BMP_SIGNATURE_0x ||
|
||||||
|
pInfo->pHeaderInfo->bytesBitmapPlanes != 1 ||
|
||||||
|
pInfo->pHeaderInfo->bytesPixelBitCount != BYTE_PER_PIXEL ||
|
||||||
|
pInfo->pHeaderInfo->bytesImageCompression != DESIRED_COMPRESSION_VALUE)
|
||||||
|
{
|
||||||
|
return (imageInfo*) freeResources(bmpFile, pInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We check if we allocated any memory to the image
|
||||||
|
We check if number of read elements from the file are different than
|
||||||
|
image size in bytes if any of this this is true then
|
||||||
|
something went wrong
|
||||||
|
*/
|
||||||
|
pInfo->pImg = malloc(pInfo->pHeaderInfo->bytesImageSize);
|
||||||
|
size_t returnedElementsData = fread((void *)pInfo->pImg,
|
||||||
|
1,
|
||||||
|
pInfo->pHeaderInfo->bytesImageSize,
|
||||||
|
bmpFile);
|
||||||
|
if( pInfo->pImg == NULL ||
|
||||||
|
returnedElementsData != pInfo->pHeaderInfo->bytesImageSize)
|
||||||
|
{
|
||||||
|
return (imageInfo*) freeResources(bmpFile, pInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fclose(bmpFile); // We can close the file
|
||||||
|
|
||||||
|
pInfo->imageWidth = pInfo->pHeaderInfo->bytesImageWidth;
|
||||||
|
pInfo->imageHeight = pInfo->pHeaderInfo->bytesImageHeight;
|
||||||
|
|
||||||
|
pInfo->bytesPerRow = pInfo->pHeaderInfo->bytesImageSize /
|
||||||
|
pInfo->pHeaderInfo->bytesImageHeight;
|
||||||
|
|
||||||
|
// bytesPerRow = imageSize / imageHeight
|
||||||
|
return pInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
int saveBMP(const imageInfo* pInfo, const char* fileName)
|
||||||
|
{
|
||||||
|
FILE *bmpFile = fopen(fileName, WRITE_AND_BINARY_MODE);
|
||||||
|
// fopen returns NULL if something went bad
|
||||||
|
// WRITE_AND_BINARY_MODE = "wb"
|
||||||
|
// cannot open file for writing
|
||||||
|
if (bmpFile == NULL) return CANNOT_OPEN_FILE_FOR_WRITING;
|
||||||
|
|
||||||
|
/* if we wrote more or less than one header then there is something wrong
|
||||||
|
if we wrote more or less bytes to the image than there are bytes in the
|
||||||
|
image then there is something wrong
|
||||||
|
CANNOT_WRITE_HEADER_OR_IMAGE = -2 */
|
||||||
|
size_t returnedHeaders = fwrite(pInfo->pHeaderInfo, sizeof(bmpHeaderInfo),
|
||||||
|
NUMBER_OF_HEADERS, bmpFile);
|
||||||
|
size_t returnedData = fwrite(pInfo->pImg, 1,
|
||||||
|
pInfo->pHeaderInfo->bytesImageSize, bmpFile);
|
||||||
|
|
||||||
|
if (returnedHeaders != NUMBER_OF_HEADERS ||
|
||||||
|
returnedData != pInfo->pHeaderInfo->bytesImageSize)
|
||||||
|
{
|
||||||
|
fclose(bmpFile); // cannot write header or image
|
||||||
|
return CANNOT_WRITE_HEADER_OR_IMAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(bmpFile);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void set_pixel(imageInfo* pImg, unsigned int x, unsigned int y,
|
||||||
|
unsigned int color)
|
||||||
|
{
|
||||||
|
/* pImg -> pImg returns the starting addres of pixels
|
||||||
|
then we calculate byte position of a pixel we want to change by:
|
||||||
|
bytesPerRow * y_coordinate + x * 3 (3 bytes for RGB)
|
||||||
|
BYTES_FOR_SINGLE_PIXEL = 3 */
|
||||||
|
unsigned char *pPix = pImg->pImg + pImg->bytesPerRow * y +
|
||||||
|
x * BYTES_FOR_SINGLE_PIXEL;
|
||||||
|
|
||||||
|
// if x and y are inside the image then we can commence forward
|
||||||
|
if (x < pImg->imageWidth || y < pImg->imageHeight)
|
||||||
|
{
|
||||||
|
*pPix = (color >> 16) & 0xFF; // R color of the pixel
|
||||||
|
*(pPix + 1) = (color >> 8) & 0xFF; // G color of the pixel
|
||||||
|
*(pPix + 2) = color & 0xFF; // B color of the pixel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int getColor(imageInfo* pImg, unsigned int x, unsigned int y)
|
||||||
|
{
|
||||||
|
char R, G, B;
|
||||||
|
if (x < pImg->imageWidth || y < pImg->imageHeight)
|
||||||
|
{
|
||||||
|
unsigned char *pPix = pImg->pImg + pImg->bytesPerRow * y +
|
||||||
|
x * BYTES_FOR_SINGLE_PIXEL;
|
||||||
|
R = *pPix;
|
||||||
|
G = *(pPix + 1);
|
||||||
|
B = *(pPix + 2);
|
||||||
|
}
|
||||||
|
unsigned int color = 0;
|
||||||
|
color = ( ((R & 0xFF) << 16) | (( G & 0xFF) << 8) | (B & 0xFF));
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
divisions userEnterDivisions()
|
||||||
|
{
|
||||||
|
divisions userDivisions;
|
||||||
|
|
||||||
|
printf(ENTER_VERTICAL_DIVISON_MESSAGE);
|
||||||
|
scanf("%d", &userDivisions.vertical);
|
||||||
|
|
||||||
|
printf(ENTER_HORIZONTAL_DIVISON_MESSAGE);
|
||||||
|
scanf("%d", &userDivisions.horizontal);
|
||||||
|
|
||||||
|
return userDivisions;
|
||||||
|
}
|
||||||
|
|
||||||
|
int calculateStartingPixelX(int pieceNumber, int horizontalDivisons,
|
||||||
|
int pieceWidth)
|
||||||
|
{
|
||||||
|
int temp = pieceNumber % horizontalDivisons;
|
||||||
|
if(temp == 0) temp = horizontalDivisons;
|
||||||
|
return (temp - 1) * pieceWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
int calculateStartingPixelY(int pieceNumber, int horizontalDivisons,
|
||||||
|
int pieceHeight)
|
||||||
|
{
|
||||||
|
return (((pieceNumber - 1) / horizontalDivisons) * pieceHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void hello_world();
|
||||||
|
|
||||||
|
int main(/*int argc, char* argv[]*/) // argc and argv[] are not used anywhere
|
||||||
|
{
|
||||||
|
|
||||||
|
imageInfo* pInfo; // imageInfo holds all header data from image
|
||||||
|
unsigned int columnIndex = 0;
|
||||||
|
|
||||||
|
// bmp header and info header should be 54 bytes as per BMP documentation
|
||||||
|
// https://www.daubnet.com/en/file-format-bmp
|
||||||
|
if (sizeof(bmpHeaderInfo) != BMP_HEADER_SIZE)
|
||||||
|
{
|
||||||
|
printf(WRONG_BMP_HEADER_SIZE_MESSAGE);
|
||||||
|
return WRONG_BMP_HEADER_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((pInfo = readBMP(SOURCE_IMAGE_NAME)) == NULL)
|
||||||
|
{
|
||||||
|
printf(ERROR_READING_SOURCE_FILE_MESSAGE);
|
||||||
|
return ERROR_READING_SOURCE_FILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
divisions pictureDivision = userEnterDivisions();
|
||||||
|
int numberOfPieces = pictureDivision.vertical * pictureDivision.horizontal;
|
||||||
|
int pieceWidth = (pInfo -> imageWidth) / pictureDivision.horizontal;
|
||||||
|
int pieceHeight = (pInfo -> imageHeight) / pictureDivision.vertical;
|
||||||
|
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
int firstPiece;
|
||||||
|
for(firstPiece = 1; firstPiece <= numberOfPieces; firstPiece++)
|
||||||
|
{
|
||||||
|
int pieceToSwapWith = rand() % numberOfPieces;
|
||||||
|
int firstPieceStartingPixelX = calculateStartingPixelX(firstPiece,
|
||||||
|
pictureDivision.horizontal,
|
||||||
|
pieceWidth);
|
||||||
|
int firstPieceStartingPixelY = calculateStartingPixelY(firstPiece,
|
||||||
|
pictureDivision.horizontal,
|
||||||
|
pieceHeight);
|
||||||
|
int secondPieceStartingPixelX = calculateStartingPixelX(pieceToSwapWith,
|
||||||
|
pictureDivision.horizontal,
|
||||||
|
pieceWidth);
|
||||||
|
int secondPieceStartingPixelY = calculateStartingPixelY(pieceToSwapWith,
|
||||||
|
pictureDivision.horizontal,
|
||||||
|
pieceHeight);
|
||||||
|
|
||||||
|
int x = 0;
|
||||||
|
for(x = 0; x < pieceWidth; x++)
|
||||||
|
{
|
||||||
|
int y = 0;
|
||||||
|
for(y = 0; y < pieceHeight; y++)
|
||||||
|
{
|
||||||
|
int firstPieceCurrentX = firstPieceStartingPixelX + x;
|
||||||
|
int firstPieceCurrentY = firstPieceStartingPixelY + y;
|
||||||
|
int secondPieceCurrentX = secondPieceStartingPixelX + x;
|
||||||
|
int secondPieceCurrentY = secondPieceStartingPixelY + y;
|
||||||
|
unsigned int firstPiecePixelColor = getColor(pInfo,
|
||||||
|
firstPieceCurrentX,
|
||||||
|
firstPieceCurrentY);
|
||||||
|
|
||||||
|
unsigned int secondPiecePixelColor = getColor(pInfo,
|
||||||
|
secondPieceCurrentX,
|
||||||
|
secondPieceCurrentY);
|
||||||
|
set_pixel(pInfo, secondPieceCurrentX,
|
||||||
|
secondPieceCurrentY, firstPiecePixelColor);
|
||||||
|
set_pixel(pInfo, firstPieceCurrentX,
|
||||||
|
firstPieceCurrentY, secondPiecePixelColor);
|
||||||
|
hello_world();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("JD\n");
|
||||||
|
|
||||||
|
saveBMP(pInfo, DESTINATION_IMAGE_NAME);
|
||||||
|
|
||||||
|
freeResources(NULL, pInfo);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
ECOAR/x86/C/puzzle.o
Executable file
BIN
ECOAR/x86/C/puzzle.o
Executable file
Binary file not shown.
727
ECOAR/x86/C/puzzle.s
Executable file
727
ECOAR/x86/C/puzzle.s
Executable file
@ -0,0 +1,727 @@
|
|||||||
|
.file "puzzle.c"
|
||||||
|
.intel_syntax noprefix
|
||||||
|
.globl _BMP_HEADER_SIZE
|
||||||
|
.section .rdata,"dr"
|
||||||
|
.align 4
|
||||||
|
_BMP_HEADER_SIZE:
|
||||||
|
.long 54
|
||||||
|
.globl _BMP_SIGNATURE_0x
|
||||||
|
.align 4
|
||||||
|
_BMP_SIGNATURE_0x:
|
||||||
|
.long 19778
|
||||||
|
.globl _NUMBER_OF_HEADERS
|
||||||
|
.align 4
|
||||||
|
_NUMBER_OF_HEADERS:
|
||||||
|
.long 1
|
||||||
|
.globl _BYTE_PER_PIXEL
|
||||||
|
.align 4
|
||||||
|
_BYTE_PER_PIXEL:
|
||||||
|
.long 24
|
||||||
|
.globl _DESIRED_COMPRESSION_VALUE
|
||||||
|
.align 4
|
||||||
|
_DESIRED_COMPRESSION_VALUE:
|
||||||
|
.space 4
|
||||||
|
.globl _CANNOT_OPEN_FILE_FOR_WRITING
|
||||||
|
.align 4
|
||||||
|
_CANNOT_OPEN_FILE_FOR_WRITING:
|
||||||
|
.long -1
|
||||||
|
.globl _CANNOT_WRITE_HEADER_OR_IMAGE
|
||||||
|
.align 4
|
||||||
|
_CANNOT_WRITE_HEADER_OR_IMAGE:
|
||||||
|
.long -2
|
||||||
|
.globl _BYTES_FOR_SINGLE_PIXEL
|
||||||
|
.align 4
|
||||||
|
_BYTES_FOR_SINGLE_PIXEL:
|
||||||
|
.long 3
|
||||||
|
.globl _WRONG_BMP_HEADER_SIZE
|
||||||
|
.align 4
|
||||||
|
_WRONG_BMP_HEADER_SIZE:
|
||||||
|
.long 1
|
||||||
|
.globl _ERROR_READING_SOURCE_FILE
|
||||||
|
.align 4
|
||||||
|
_ERROR_READING_SOURCE_FILE:
|
||||||
|
.long 2
|
||||||
|
.globl _ENTER_VERTICAL_DIVISON_MESSAGE
|
||||||
|
.align 32
|
||||||
|
_ENTER_VERTICAL_DIVISON_MESSAGE:
|
||||||
|
.ascii "Enter number of vertical divisons: \0"
|
||||||
|
.globl _ENTER_HORIZONTAL_DIVISON_MESSAGE
|
||||||
|
.align 32
|
||||||
|
_ENTER_HORIZONTAL_DIVISON_MESSAGE:
|
||||||
|
.ascii "Enter number of horizontal divisons: \0"
|
||||||
|
.globl _WRONG_BMP_HEADER_SIZE_MESSAGE
|
||||||
|
.align 32
|
||||||
|
_WRONG_BMP_HEADER_SIZE_MESSAGE:
|
||||||
|
.ascii "Check compilation options so as bmpHeaderInfo struct size is 54 bytes.\12\0"
|
||||||
|
.globl _READ_AND_BINARY_MODE
|
||||||
|
_READ_AND_BINARY_MODE:
|
||||||
|
.ascii "rb\0"
|
||||||
|
.globl _WRITE_AND_BINARY_MODE
|
||||||
|
_WRITE_AND_BINARY_MODE:
|
||||||
|
.ascii "wb\0"
|
||||||
|
.globl _SOURCE_IMAGE_NAME
|
||||||
|
_SOURCE_IMAGE_NAME:
|
||||||
|
.ascii "source.bmp\0"
|
||||||
|
.globl _DESTINATION_IMAGE_NAME
|
||||||
|
_DESTINATION_IMAGE_NAME:
|
||||||
|
.ascii "dest.bmp\0"
|
||||||
|
.globl _ERROR_READING_SOURCE_FILE_MESSAGE
|
||||||
|
.align 32
|
||||||
|
_ERROR_READING_SOURCE_FILE_MESSAGE:
|
||||||
|
.ascii "Error reading source file (probably).\12\0"
|
||||||
|
.text
|
||||||
|
.globl _allocateSpaceForImageInfo
|
||||||
|
.def _allocateSpaceForImageInfo; .scl 2; .type 32; .endef
|
||||||
|
_allocateSpaceForImageInfo:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 40
|
||||||
|
mov DWORD PTR [esp], 20
|
||||||
|
call _malloc
|
||||||
|
mov DWORD PTR [ebp-12], eax
|
||||||
|
cmp DWORD PTR [ebp-12], 0
|
||||||
|
je L2
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax], 0
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax+4], 0
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax+8], 0
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax+12], 0
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax+16], 0
|
||||||
|
L2:
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
.globl _freeImageInfo
|
||||||
|
.def _freeImageInfo; .scl 2; .type 32; .endef
|
||||||
|
_freeImageInfo:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 24
|
||||||
|
cmp DWORD PTR [ebp+8], 0
|
||||||
|
je L5
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+12]
|
||||||
|
test eax, eax
|
||||||
|
je L6
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+12]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _free
|
||||||
|
L6:
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
test eax, eax
|
||||||
|
je L7
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _free
|
||||||
|
L7:
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _free
|
||||||
|
L5:
|
||||||
|
mov eax, 0
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
.globl _freeResources
|
||||||
|
.def _freeResources; .scl 2; .type 32; .endef
|
||||||
|
_freeResources:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 24
|
||||||
|
cmp DWORD PTR [ebp+8], 0
|
||||||
|
je L10
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fclose
|
||||||
|
L10:
|
||||||
|
mov eax, DWORD PTR [ebp+12]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _freeImageInfo
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
.globl _readBMP
|
||||||
|
.def _readBMP; .scl 2; .type 32; .endef
|
||||||
|
_readBMP:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
push ebx
|
||||||
|
sub esp, 36
|
||||||
|
mov DWORD PTR [ebp-12], 0
|
||||||
|
mov DWORD PTR [ebp-16], 0
|
||||||
|
call _allocateSpaceForImageInfo
|
||||||
|
mov DWORD PTR [ebp-12], eax
|
||||||
|
cmp DWORD PTR [ebp-12], 0
|
||||||
|
jne L13
|
||||||
|
mov eax, 0
|
||||||
|
jmp L14
|
||||||
|
L13:
|
||||||
|
mov DWORD PTR [esp+4], OFFSET FLAT:_READ_AND_BINARY_MODE
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fopen
|
||||||
|
mov DWORD PTR [ebp-16], eax
|
||||||
|
cmp DWORD PTR [ebp-16], 0
|
||||||
|
jne L15
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [ebp-16]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _freeResources
|
||||||
|
jmp L14
|
||||||
|
L15:
|
||||||
|
mov DWORD PTR [esp], 54
|
||||||
|
call _malloc
|
||||||
|
mov edx, eax
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax+16], edx
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
test eax, eax
|
||||||
|
je L16
|
||||||
|
mov eax, 1
|
||||||
|
mov edx, eax
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov ecx, DWORD PTR [ebp-16]
|
||||||
|
mov DWORD PTR [esp+12], ecx
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], 54
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fread
|
||||||
|
mov edx, 1
|
||||||
|
cmp eax, edx
|
||||||
|
je L17
|
||||||
|
L16:
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [ebp-16]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _freeResources
|
||||||
|
jmp L14
|
||||||
|
L17:
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
movzx eax, WORD PTR [eax]
|
||||||
|
movzx edx, ax
|
||||||
|
mov eax, 19778
|
||||||
|
cmp edx, eax
|
||||||
|
jne L18
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
movzx eax, WORD PTR [eax+26]
|
||||||
|
cmp ax, 1
|
||||||
|
jne L18
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
movzx eax, WORD PTR [eax+28]
|
||||||
|
movsx edx, ax
|
||||||
|
mov eax, 24
|
||||||
|
cmp edx, eax
|
||||||
|
jne L18
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov edx, DWORD PTR [eax+30]
|
||||||
|
mov eax, 0
|
||||||
|
cmp edx, eax
|
||||||
|
je L19
|
||||||
|
L18:
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [ebp-16]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _freeResources
|
||||||
|
jmp L14
|
||||||
|
L19:
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov eax, DWORD PTR [eax+34]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _malloc
|
||||||
|
mov edx, eax
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax+12], edx
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+12]
|
||||||
|
test eax, eax
|
||||||
|
je L20
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov edx, DWORD PTR [eax+34]
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+12]
|
||||||
|
mov ecx, DWORD PTR [ebp-16]
|
||||||
|
mov DWORD PTR [esp+12], ecx
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], 1
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fread
|
||||||
|
mov edx, DWORD PTR [ebp-12]
|
||||||
|
mov edx, DWORD PTR [edx+16]
|
||||||
|
mov edx, DWORD PTR [edx+34]
|
||||||
|
cmp eax, edx
|
||||||
|
je L21
|
||||||
|
L20:
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [ebp-16]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _freeResources
|
||||||
|
jmp L14
|
||||||
|
L21:
|
||||||
|
mov eax, DWORD PTR [ebp-16]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fclose
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov eax, DWORD PTR [eax+18]
|
||||||
|
mov edx, eax
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax], edx
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov eax, DWORD PTR [eax+22]
|
||||||
|
mov edx, eax
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax+4], edx
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov eax, DWORD PTR [eax+34]
|
||||||
|
mov edx, DWORD PTR [ebp-12]
|
||||||
|
mov edx, DWORD PTR [edx+16]
|
||||||
|
mov edx, DWORD PTR [edx+22]
|
||||||
|
mov ebx, edx
|
||||||
|
mov edx, 0
|
||||||
|
div ebx
|
||||||
|
mov edx, eax
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [eax+8], edx
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
L14:
|
||||||
|
add esp, 36
|
||||||
|
pop ebx
|
||||||
|
pop ebp
|
||||||
|
ret
|
||||||
|
.globl _saveBMP
|
||||||
|
.def _saveBMP; .scl 2; .type 32; .endef
|
||||||
|
_saveBMP:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 40
|
||||||
|
mov DWORD PTR [esp+4], OFFSET FLAT:_WRITE_AND_BINARY_MODE
|
||||||
|
mov eax, DWORD PTR [ebp+12]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fopen
|
||||||
|
mov DWORD PTR [ebp-12], eax
|
||||||
|
cmp DWORD PTR [ebp-12], 0
|
||||||
|
jne L23
|
||||||
|
mov eax, -1
|
||||||
|
jmp L24
|
||||||
|
L23:
|
||||||
|
mov eax, 1
|
||||||
|
mov edx, eax
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov ecx, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [esp+12], ecx
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], 54
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fwrite
|
||||||
|
mov edx, 1
|
||||||
|
cmp eax, edx
|
||||||
|
jne L25
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+16]
|
||||||
|
mov edx, DWORD PTR [eax+34]
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+12]
|
||||||
|
mov ecx, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [esp+12], ecx
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], 1
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fwrite
|
||||||
|
mov edx, DWORD PTR [ebp+8]
|
||||||
|
mov edx, DWORD PTR [edx+16]
|
||||||
|
mov edx, DWORD PTR [edx+34]
|
||||||
|
cmp eax, edx
|
||||||
|
je L26
|
||||||
|
L25:
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fclose
|
||||||
|
mov eax, -2
|
||||||
|
jmp L24
|
||||||
|
L26:
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _fclose
|
||||||
|
mov eax, 0
|
||||||
|
L24:
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
.globl _set_pixel
|
||||||
|
.def _set_pixel; .scl 2; .type 32; .endef
|
||||||
|
_set_pixel:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 16
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov edx, DWORD PTR [eax+12]
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+8]
|
||||||
|
imul eax, DWORD PTR [ebp+16]
|
||||||
|
mov ecx, eax
|
||||||
|
mov eax, 3
|
||||||
|
imul eax, DWORD PTR [ebp+12]
|
||||||
|
add eax, ecx
|
||||||
|
add eax, edx
|
||||||
|
mov DWORD PTR [ebp-4], eax
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax]
|
||||||
|
cmp eax, DWORD PTR [ebp+12]
|
||||||
|
ja L28
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+4]
|
||||||
|
cmp eax, DWORD PTR [ebp+16]
|
||||||
|
jbe L27
|
||||||
|
L28:
|
||||||
|
mov eax, DWORD PTR [ebp+20]
|
||||||
|
shr eax, 16
|
||||||
|
mov edx, eax
|
||||||
|
mov eax, DWORD PTR [ebp-4]
|
||||||
|
mov BYTE PTR [eax], dl
|
||||||
|
mov eax, DWORD PTR [ebp-4]
|
||||||
|
lea edx, [eax+1]
|
||||||
|
mov eax, DWORD PTR [ebp+20]
|
||||||
|
shr eax, 8
|
||||||
|
mov BYTE PTR [edx], al
|
||||||
|
mov eax, DWORD PTR [ebp-4]
|
||||||
|
lea edx, [eax+2]
|
||||||
|
mov eax, DWORD PTR [ebp+20]
|
||||||
|
mov BYTE PTR [edx], al
|
||||||
|
L27:
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
.globl _getColor
|
||||||
|
.def _getColor; .scl 2; .type 32; .endef
|
||||||
|
_getColor:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 16
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax]
|
||||||
|
cmp eax, DWORD PTR [ebp+12]
|
||||||
|
ja L31
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+4]
|
||||||
|
cmp eax, DWORD PTR [ebp+16]
|
||||||
|
jbe L32
|
||||||
|
L31:
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov edx, DWORD PTR [eax+12]
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
mov eax, DWORD PTR [eax+8]
|
||||||
|
imul eax, DWORD PTR [ebp+16]
|
||||||
|
mov ecx, eax
|
||||||
|
mov eax, 3
|
||||||
|
imul eax, DWORD PTR [ebp+12]
|
||||||
|
add eax, ecx
|
||||||
|
add eax, edx
|
||||||
|
mov DWORD PTR [ebp-8], eax
|
||||||
|
mov eax, DWORD PTR [ebp-8]
|
||||||
|
movzx eax, BYTE PTR [eax]
|
||||||
|
mov BYTE PTR [ebp-1], al
|
||||||
|
mov eax, DWORD PTR [ebp-8]
|
||||||
|
add eax, 1
|
||||||
|
movzx eax, BYTE PTR [eax]
|
||||||
|
mov BYTE PTR [ebp-2], al
|
||||||
|
mov eax, DWORD PTR [ebp-8]
|
||||||
|
add eax, 2
|
||||||
|
movzx eax, BYTE PTR [eax]
|
||||||
|
mov BYTE PTR [ebp-3], al
|
||||||
|
L32:
|
||||||
|
mov DWORD PTR [ebp-12], 0
|
||||||
|
movsx eax, BYTE PTR [ebp-1]
|
||||||
|
movzx eax, al
|
||||||
|
sal eax, 16
|
||||||
|
mov edx, eax
|
||||||
|
movsx eax, BYTE PTR [ebp-2]
|
||||||
|
sal eax, 8
|
||||||
|
movzx eax, ax
|
||||||
|
or edx, eax
|
||||||
|
movsx eax, BYTE PTR [ebp-3]
|
||||||
|
movzx eax, al
|
||||||
|
or eax, edx
|
||||||
|
mov DWORD PTR [ebp-12], eax
|
||||||
|
mov eax, DWORD PTR [ebp-12]
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
.section .rdata,"dr"
|
||||||
|
LC0:
|
||||||
|
.ascii "%d\0"
|
||||||
|
.text
|
||||||
|
.globl _userEnterDivisions
|
||||||
|
.def _userEnterDivisions; .scl 2; .type 32; .endef
|
||||||
|
_userEnterDivisions:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 40
|
||||||
|
mov DWORD PTR [esp], OFFSET FLAT:_ENTER_VERTICAL_DIVISON_MESSAGE
|
||||||
|
call _printf
|
||||||
|
lea eax, [ebp-16]
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov DWORD PTR [esp], OFFSET FLAT:LC0
|
||||||
|
call _scanf
|
||||||
|
mov DWORD PTR [esp], OFFSET FLAT:_ENTER_HORIZONTAL_DIVISON_MESSAGE
|
||||||
|
call _printf
|
||||||
|
lea eax, [ebp-16]
|
||||||
|
add eax, 4
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov DWORD PTR [esp], OFFSET FLAT:LC0
|
||||||
|
call _scanf
|
||||||
|
mov eax, DWORD PTR [ebp-16]
|
||||||
|
mov edx, DWORD PTR [ebp-12]
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
.globl _calculateStartingPixelX
|
||||||
|
.def _calculateStartingPixelX; .scl 2; .type 32; .endef
|
||||||
|
_calculateStartingPixelX:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 16
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
cdq
|
||||||
|
idiv DWORD PTR [ebp+12]
|
||||||
|
mov DWORD PTR [ebp-4], edx
|
||||||
|
cmp DWORD PTR [ebp-4], 0
|
||||||
|
jne L37
|
||||||
|
mov eax, DWORD PTR [ebp+12]
|
||||||
|
mov DWORD PTR [ebp-4], eax
|
||||||
|
L37:
|
||||||
|
mov eax, DWORD PTR [ebp-4]
|
||||||
|
sub eax, 1
|
||||||
|
imul eax, DWORD PTR [ebp+16]
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
.globl _calculateStartingPixelY
|
||||||
|
.def _calculateStartingPixelY; .scl 2; .type 32; .endef
|
||||||
|
_calculateStartingPixelY:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
mov eax, DWORD PTR [ebp+8]
|
||||||
|
sub eax, 1
|
||||||
|
cdq
|
||||||
|
idiv DWORD PTR [ebp+12]
|
||||||
|
imul eax, DWORD PTR [ebp+16]
|
||||||
|
pop ebp
|
||||||
|
ret
|
||||||
|
.def ___main; .scl 2; .type 32; .endef
|
||||||
|
.section .rdata,"dr"
|
||||||
|
.align 4
|
||||||
|
LC1:
|
||||||
|
.ascii "Check compilation options so as bmpHeaderInfo struct size is 54 bytes.\0"
|
||||||
|
.align 4
|
||||||
|
LC2:
|
||||||
|
.ascii "Error reading source file (probably).\0"
|
||||||
|
.text
|
||||||
|
.globl _main
|
||||||
|
.def _main; .scl 2; .type 32; .endef
|
||||||
|
_main:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
push esi
|
||||||
|
push ebx
|
||||||
|
and esp, -16
|
||||||
|
sub esp, 112
|
||||||
|
call ___main
|
||||||
|
mov DWORD PTR [esp+96], 0
|
||||||
|
mov eax, 54
|
||||||
|
cmp eax, 54
|
||||||
|
je L42
|
||||||
|
mov DWORD PTR [esp], OFFSET FLAT:LC1
|
||||||
|
call _puts
|
||||||
|
mov eax, 1
|
||||||
|
jmp L51
|
||||||
|
L42:
|
||||||
|
mov DWORD PTR [esp], OFFSET FLAT:_SOURCE_IMAGE_NAME
|
||||||
|
call _readBMP
|
||||||
|
mov DWORD PTR [esp+92], eax
|
||||||
|
cmp DWORD PTR [esp+92], 0
|
||||||
|
jne L44
|
||||||
|
mov DWORD PTR [esp], OFFSET FLAT:LC2
|
||||||
|
call _puts
|
||||||
|
mov eax, 2
|
||||||
|
jmp L51
|
||||||
|
L44:
|
||||||
|
call _userEnterDivisions
|
||||||
|
mov DWORD PTR [esp+28], eax
|
||||||
|
mov DWORD PTR [esp+32], edx
|
||||||
|
mov edx, DWORD PTR [esp+28]
|
||||||
|
mov eax, DWORD PTR [esp+32]
|
||||||
|
imul eax, edx
|
||||||
|
mov DWORD PTR [esp+88], eax
|
||||||
|
mov eax, DWORD PTR [esp+92]
|
||||||
|
mov eax, DWORD PTR [eax]
|
||||||
|
mov edx, DWORD PTR [esp+32]
|
||||||
|
mov ebx, edx
|
||||||
|
mov edx, 0
|
||||||
|
div ebx
|
||||||
|
mov DWORD PTR [esp+84], eax
|
||||||
|
mov eax, DWORD PTR [esp+92]
|
||||||
|
mov eax, DWORD PTR [eax+4]
|
||||||
|
mov edx, DWORD PTR [esp+28]
|
||||||
|
mov esi, edx
|
||||||
|
mov edx, 0
|
||||||
|
div esi
|
||||||
|
mov DWORD PTR [esp+80], eax
|
||||||
|
mov DWORD PTR [esp], 0
|
||||||
|
call _time
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _srand
|
||||||
|
mov DWORD PTR [esp+108], 1
|
||||||
|
jmp L45
|
||||||
|
L50:
|
||||||
|
call _rand
|
||||||
|
cdq
|
||||||
|
idiv DWORD PTR [esp+88]
|
||||||
|
mov DWORD PTR [esp+76], edx
|
||||||
|
mov eax, DWORD PTR [esp+32]
|
||||||
|
mov edx, DWORD PTR [esp+84]
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [esp+108]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _calculateStartingPixelX
|
||||||
|
mov DWORD PTR [esp+72], eax
|
||||||
|
mov eax, DWORD PTR [esp+32]
|
||||||
|
mov edx, DWORD PTR [esp+80]
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [esp+108]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _calculateStartingPixelY
|
||||||
|
mov DWORD PTR [esp+68], eax
|
||||||
|
mov eax, DWORD PTR [esp+32]
|
||||||
|
mov edx, DWORD PTR [esp+84]
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [esp+76]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _calculateStartingPixelX
|
||||||
|
mov DWORD PTR [esp+64], eax
|
||||||
|
mov eax, DWORD PTR [esp+32]
|
||||||
|
mov edx, DWORD PTR [esp+80]
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [esp+76]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _calculateStartingPixelY
|
||||||
|
mov DWORD PTR [esp+60], eax
|
||||||
|
mov DWORD PTR [esp+104], 0
|
||||||
|
mov DWORD PTR [esp+104], 0
|
||||||
|
jmp L46
|
||||||
|
L49:
|
||||||
|
mov DWORD PTR [esp+100], 0
|
||||||
|
mov DWORD PTR [esp+100], 0
|
||||||
|
jmp L47
|
||||||
|
L48:
|
||||||
|
mov eax, DWORD PTR [esp+104]
|
||||||
|
mov edx, DWORD PTR [esp+72]
|
||||||
|
add eax, edx
|
||||||
|
mov DWORD PTR [esp+56], eax
|
||||||
|
mov eax, DWORD PTR [esp+100]
|
||||||
|
mov edx, DWORD PTR [esp+68]
|
||||||
|
add eax, edx
|
||||||
|
mov DWORD PTR [esp+52], eax
|
||||||
|
mov eax, DWORD PTR [esp+104]
|
||||||
|
mov edx, DWORD PTR [esp+64]
|
||||||
|
add eax, edx
|
||||||
|
mov DWORD PTR [esp+48], eax
|
||||||
|
mov eax, DWORD PTR [esp+100]
|
||||||
|
mov edx, DWORD PTR [esp+60]
|
||||||
|
add eax, edx
|
||||||
|
mov DWORD PTR [esp+44], eax
|
||||||
|
mov edx, DWORD PTR [esp+52]
|
||||||
|
mov eax, DWORD PTR [esp+56]
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [esp+92]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _getColor
|
||||||
|
mov DWORD PTR [esp+40], eax
|
||||||
|
mov edx, DWORD PTR [esp+44]
|
||||||
|
mov eax, DWORD PTR [esp+48]
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [esp+92]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _getColor
|
||||||
|
mov DWORD PTR [esp+36], eax
|
||||||
|
mov edx, DWORD PTR [esp+44]
|
||||||
|
mov eax, DWORD PTR [esp+48]
|
||||||
|
mov ecx, DWORD PTR [esp+40]
|
||||||
|
mov DWORD PTR [esp+12], ecx
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [esp+92]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _set_pixel
|
||||||
|
mov edx, DWORD PTR [esp+52]
|
||||||
|
mov eax, DWORD PTR [esp+56]
|
||||||
|
mov ecx, DWORD PTR [esp+36]
|
||||||
|
mov DWORD PTR [esp+12], ecx
|
||||||
|
mov DWORD PTR [esp+8], edx
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov eax, DWORD PTR [esp+92]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _set_pixel
|
||||||
|
add DWORD PTR [esp+100], 1
|
||||||
|
L47:
|
||||||
|
mov eax, DWORD PTR [esp+100]
|
||||||
|
cmp eax, DWORD PTR [esp+80]
|
||||||
|
jl L48
|
||||||
|
add DWORD PTR [esp+104], 1
|
||||||
|
L46:
|
||||||
|
mov eax, DWORD PTR [esp+104]
|
||||||
|
cmp eax, DWORD PTR [esp+84]
|
||||||
|
jl L49
|
||||||
|
add DWORD PTR [esp+108], 1
|
||||||
|
L45:
|
||||||
|
mov eax, DWORD PTR [esp+108]
|
||||||
|
cmp eax, DWORD PTR [esp+88]
|
||||||
|
jle L50
|
||||||
|
mov DWORD PTR [esp+4], OFFSET FLAT:_DESTINATION_IMAGE_NAME
|
||||||
|
mov eax, DWORD PTR [esp+92]
|
||||||
|
mov DWORD PTR [esp], eax
|
||||||
|
call _saveBMP
|
||||||
|
mov eax, DWORD PTR [esp+92]
|
||||||
|
mov DWORD PTR [esp+4], eax
|
||||||
|
mov DWORD PTR [esp], 0
|
||||||
|
call _freeResources
|
||||||
|
mov eax, 0
|
||||||
|
L51:
|
||||||
|
lea esp, [ebp-8]
|
||||||
|
pop ebx
|
||||||
|
pop esi
|
||||||
|
pop ebp
|
||||||
|
ret
|
||||||
|
.ident "GCC: (GNU) 4.8.3"
|
||||||
|
.def _malloc; .scl 2; .type 32; .endef
|
||||||
|
.def _free; .scl 2; .type 32; .endef
|
||||||
|
.def _fclose; .scl 2; .type 32; .endef
|
||||||
|
.def _fopen; .scl 2; .type 32; .endef
|
||||||
|
.def _fread; .scl 2; .type 32; .endef
|
||||||
|
.def _fwrite; .scl 2; .type 32; .endef
|
||||||
|
.def _printf; .scl 2; .type 32; .endef
|
||||||
|
.def _scanf; .scl 2; .type 32; .endef
|
||||||
|
.def _puts; .scl 2; .type 32; .endef
|
||||||
|
.def _time; .scl 2; .type 32; .endef
|
||||||
|
.def _srand; .scl 2; .type 32; .endef
|
||||||
|
.def _rand; .scl 2; .type 32; .endef
|
||||||
BIN
ECOAR/x86/C/puzzle_test.out
Executable file
BIN
ECOAR/x86/C/puzzle_test.out
Executable file
Binary file not shown.
BIN
ECOAR/x86/C/source.bmp
Executable file
BIN
ECOAR/x86/C/source.bmp
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 225 KiB |
Loading…
Reference in New Issue
Block a user