ACTUALLY adding x86 code that handles puzzle generation
136
ECOAR/C/asm_part.asm
Executable file
@ -0,0 +1,136 @@
|
||||
|
||||
|
||||
section .data
|
||||
|
||||
|
||||
|
||||
image_info_address EQU 8 ; First argument passed to our function starts from 8
|
||||
first_piece_address EQU 12 ; From that point we just add 4 to address of next
|
||||
; arguments
|
||||
piece_to_swap_with_address EQU 16
|
||||
horizontal_divisons_address EQU 20
|
||||
piece_width_address EQU 24
|
||||
piece_height_address EQU 28
|
||||
piece_width_bytes_address EQU 32
|
||||
piece_height_bytes_address EQU 36
|
||||
bytes_per_row_address EQU 40
|
||||
firstPieceStartingByte EQU 44
|
||||
secondPieceStartingByte EQU 48
|
||||
|
||||
|
||||
pImg_inside_image_info_address EQU 12
|
||||
|
||||
|
||||
image_width EQU 0
|
||||
image_height EQU 4
|
||||
bytes_per_row_inside_image_info_address EQU 8
|
||||
image_pImg EQU 12
|
||||
image_pHeaderInfo EQU 16 ; not really used
|
||||
|
||||
; first.X, first.Y, second.X, second.Y
|
||||
|
||||
|
||||
|
||||
%macro print 2 ;number of arguments this macro takes
|
||||
mov edx, %1 ;message length
|
||||
mov ecx, %2 ;message to write
|
||||
mov ebx,1 ;file descriptor (stdout)
|
||||
mov eax,4 ;system call number (sys_write)
|
||||
int 0x80 ;call kernel
|
||||
%endmacro
|
||||
|
||||
|
||||
|
||||
section .text
|
||||
global inner_loops ;must be declared for linker (ld)
|
||||
; extern void hello_world(imageInfo* pInfo, int firstPiece, int pieceToSwapWith,
|
||||
; int horizontalDivisions, int pieceWidth,
|
||||
; int pieceHeight);
|
||||
|
||||
; mov ecx, [ebp + 8] ; ecx <- address of imgInfo struct, not saved
|
||||
; mov eax, [ebp + 12] ; eax <- firstPiece, not saved
|
||||
; mov edx, [ebp + 16] ; edx <- pieceToSwapWith, not saved
|
||||
; mov esi, [ecx + image_pImg] ; esi <- start of pixels in picture, saved
|
||||
; mov ebx, [ebp + 20] ; ebx <- horizontalDivisions
|
||||
; mov edi, [ebp + 24] ; edi <- pieceWidth
|
||||
|
||||
inner_loops: ;tells linker entry point
|
||||
|
||||
push ebp ; as per calling convention we need to keep the values of
|
||||
; certain registers
|
||||
mov ebp,esp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
|
||||
; what we use:
|
||||
; ecx - firstPieceFirstByteAddress
|
||||
; edx - secondPieceFirstByteAddress
|
||||
; esi
|
||||
; edi
|
||||
|
||||
; what we have:
|
||||
; eax
|
||||
; ebx
|
||||
|
||||
push ebx
|
||||
push eax
|
||||
;mov eax, [ebp + firstPieceStartingByte]
|
||||
;mov eax, [eax + image_pImg]
|
||||
mov edi, 0
|
||||
|
||||
x_pixels_loop:
|
||||
cmp edi, [ebp + piece_width_bytes_address]
|
||||
;cmp edi, 300
|
||||
jge x_pixels_loop_end
|
||||
mov esi, 0
|
||||
|
||||
; ecx = secondPieceStartingByte
|
||||
; edx = firstPieceStartingByte
|
||||
; we still have eax and ebx
|
||||
;
|
||||
y_pixels_loop:
|
||||
cmp esi, [ebp + piece_height_bytes_address]
|
||||
;cmp esi, 96000
|
||||
jge y_pixels_loop_end
|
||||
mov ecx, [ebp + secondPieceStartingByte]
|
||||
mov eax, [ebp + firstPieceStartingByte]
|
||||
add ecx, edi
|
||||
add ecx, esi
|
||||
add eax, edi
|
||||
add eax, esi
|
||||
|
||||
mov BYTE bl, [eax]
|
||||
mov BYTE dl, [ecx]
|
||||
mov BYTE[ecx], bl
|
||||
mov BYTE[eax], dl
|
||||
|
||||
mov BYTE bl, [eax + 1]
|
||||
mov BYTE dl, [ecx + 1]
|
||||
mov BYTE[ecx + 1], bl
|
||||
mov BYTE[eax + 1], dl
|
||||
|
||||
mov BYTE bl, [eax + 2]
|
||||
mov BYTE dl, [ecx + 2]
|
||||
mov BYTE[ecx + 2], bl
|
||||
mov BYTE[eax + 2], dl
|
||||
|
||||
|
||||
|
||||
add esi, [ebp + bytes_per_row_address]
|
||||
jmp y_pixels_loop
|
||||
|
||||
|
||||
; for(x = 0; x < pieceWidth * 3; x += 3)
|
||||
y_pixels_loop_end:
|
||||
add edi, 3
|
||||
jmp x_pixels_loop
|
||||
|
||||
x_pixels_loop_end:
|
||||
|
||||
pop esi
|
||||
pop edi
|
||||
pop ebx
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
136
ECOAR/C/asm_part.lst
Normal file
@ -0,0 +1,136 @@
|
||||
1
|
||||
2
|
||||
3 section .data
|
||||
4
|
||||
5
|
||||
6
|
||||
7 image_info_address EQU 8 ; First argument passed to our function starts from 8
|
||||
8 first_piece_address EQU 12 ; From that point we just add 4 to address of next
|
||||
9 ; arguments
|
||||
10 piece_to_swap_with_address EQU 16
|
||||
11 horizontal_divisons_address EQU 20
|
||||
12 piece_width_address EQU 24
|
||||
13 piece_height_address EQU 28
|
||||
14 piece_width_bytes_address EQU 32
|
||||
15 piece_height_bytes_address EQU 36
|
||||
16 bytes_per_row_address EQU 40
|
||||
17 firstPieceStartingByte EQU 44
|
||||
18 secondPieceStartingByte EQU 48
|
||||
19
|
||||
20
|
||||
21 pImg_inside_image_info_address EQU 12
|
||||
22
|
||||
23
|
||||
24 image_width EQU 0
|
||||
25 image_height EQU 4
|
||||
26 bytes_per_row_inside_image_info_address EQU 8
|
||||
27 image_pImg EQU 12
|
||||
28 image_pHeaderInfo EQU 16 ; not really used
|
||||
29
|
||||
30 ; first.X, first.Y, second.X, second.Y
|
||||
31
|
||||
32
|
||||
33
|
||||
34 %macro print 2 ;number of arguments this macro takes
|
||||
35 mov edx, %1 ;message length
|
||||
36 mov ecx, %2 ;message to write
|
||||
37 mov ebx,1 ;file descriptor (stdout)
|
||||
38 mov eax,4 ;system call number (sys_write)
|
||||
39 int 0x80 ;call kernel
|
||||
40 %endmacro
|
||||
41
|
||||
42
|
||||
43
|
||||
44 section .text
|
||||
45 global inner_loops ;must be declared for linker (ld)
|
||||
46 ; extern void hello_world(imageInfo* pInfo, int firstPiece, int pieceToSwapWith,
|
||||
47 ; int horizontalDivisions, int pieceWidth,
|
||||
48 ; int pieceHeight);
|
||||
49
|
||||
50 ; mov ecx, [ebp + 8] ; ecx <- address of imgInfo struct, not saved
|
||||
51 ; mov eax, [ebp + 12] ; eax <- firstPiece, not saved
|
||||
52 ; mov edx, [ebp + 16] ; edx <- pieceToSwapWith, not saved
|
||||
53 ; mov esi, [ecx + image_pImg] ; esi <- start of pixels in picture, saved
|
||||
54 ; mov ebx, [ebp + 20] ; ebx <- horizontalDivisions
|
||||
55 ; mov edi, [ebp + 24] ; edi <- pieceWidth
|
||||
56
|
||||
57 inner_loops: ;tells linker entry point
|
||||
58
|
||||
59 00000000 55 push ebp ; as per calling convention we need to keep the values of
|
||||
60 ; certain registers
|
||||
61 00000001 89E5 mov ebp,esp
|
||||
62 00000003 53 push ebx
|
||||
63 00000004 56 push esi
|
||||
64 00000005 57 push edi
|
||||
65
|
||||
66 ; what we use:
|
||||
67 ; ecx - firstPieceFirstByteAddress
|
||||
68 ; edx - secondPieceFirstByteAddress
|
||||
69 ; esi
|
||||
70 ; edi
|
||||
71
|
||||
72 ; what we have:
|
||||
73 ; eax
|
||||
74 ; ebx
|
||||
75
|
||||
76 00000006 53 push ebx
|
||||
77 00000007 50 push eax
|
||||
78 ;mov eax, [ebp + firstPieceStartingByte]
|
||||
79 ;mov eax, [eax + image_pImg]
|
||||
80 00000008 BF00000000 mov edi, 0
|
||||
81
|
||||
82 x_pixels_loop:
|
||||
83 0000000D 3B7D20 cmp edi, [ebp + piece_width_bytes_address]
|
||||
84 ;cmp edi, 300
|
||||
85 00000010 7D42 jge x_pixels_loop_end
|
||||
86 00000012 BE00000000 mov esi, 0
|
||||
87
|
||||
88 ; ecx = secondPieceStartingByte
|
||||
89 ; edx = firstPieceStartingByte
|
||||
90 ; we still have eax and ebx
|
||||
91 ;
|
||||
92 y_pixels_loop:
|
||||
93 00000017 3B7524 cmp esi, [ebp + piece_height_bytes_address]
|
||||
94 ;cmp esi, 96000
|
||||
95 0000001A 7D33 jge y_pixels_loop_end
|
||||
96 0000001C 8B4D30 mov ecx, [ebp + secondPieceStartingByte]
|
||||
97 0000001F 8B452C mov eax, [ebp + firstPieceStartingByte]
|
||||
98 00000022 01F9 add ecx, edi
|
||||
99 00000024 01F1 add ecx, esi
|
||||
100 00000026 01F8 add eax, edi
|
||||
101 00000028 01F0 add eax, esi
|
||||
102
|
||||
103 0000002A 8A18 mov BYTE bl, [eax]
|
||||
104 0000002C 8A11 mov BYTE dl, [ecx]
|
||||
105 0000002E 8819 mov BYTE[ecx], bl
|
||||
106 00000030 8810 mov BYTE[eax], dl
|
||||
107
|
||||
108 00000032 8A5801 mov BYTE bl, [eax + 1]
|
||||
109 00000035 8A5101 mov BYTE dl, [ecx + 1]
|
||||
110 00000038 885901 mov BYTE[ecx + 1], bl
|
||||
111 0000003B 885001 mov BYTE[eax + 1], dl
|
||||
112
|
||||
113 0000003E 8A5802 mov BYTE bl, [eax + 2]
|
||||
114 00000041 8A5102 mov BYTE dl, [ecx + 2]
|
||||
115 00000044 885902 mov BYTE[ecx + 2], bl
|
||||
116 00000047 885002 mov BYTE[eax + 2], dl
|
||||
117
|
||||
118
|
||||
119
|
||||
120 0000004A 037528 add esi, [ebp + bytes_per_row_address]
|
||||
121 0000004D EBC8 jmp y_pixels_loop
|
||||
122
|
||||
123
|
||||
124 ; for(x = 0; x < pieceWidth * 3; x += 3)
|
||||
125 y_pixels_loop_end:
|
||||
126 0000004F 83C703 add edi, 3
|
||||
127 00000052 EBB9 jmp x_pixels_loop
|
||||
128
|
||||
129 x_pixels_loop_end:
|
||||
130
|
||||
131 00000054 5E pop esi
|
||||
132 00000055 5F pop edi
|
||||
133 00000056 5B pop ebx
|
||||
134 00000057 89EC mov esp, ebp
|
||||
135 00000059 5D pop ebp
|
||||
136 0000005A C3 ret
|
||||
BIN
ECOAR/C/asm_part.o
Normal file
BIN
ECOAR/C/dest.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
14
ECOAR/C/makefile
Executable file
@ -0,0 +1,14 @@
|
||||
CC=gcc
|
||||
ASMBIN=nasm
|
||||
|
||||
all : asm cc link
|
||||
asm :
|
||||
$(ASMBIN) -o asm_part.o -f elf32 -g -l asm_part.lst asm_part.asm
|
||||
cc :
|
||||
$(CC) -m32 -c -g -O0 puzzle.c
|
||||
link :
|
||||
$(CC) -m32 -g -o puzzle.out -g puzzle.o asm_part.o -no-pie
|
||||
clean :
|
||||
rm *.o
|
||||
rm setcol_test
|
||||
rm asm_part.lst
|
||||
BIN
ECOAR/C/pictures/source.bmp
Executable file
|
After Width: | Height: | Size: 225 KiB |
@ -80,7 +80,8 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int imageWidth, imageHeight; // same as in bmpHeaderInfo
|
||||
unsigned int imageWidth;
|
||||
unsigned int imageHeight; // same as in bmpHeaderInfo
|
||||
unsigned int bytesPerRow;
|
||||
// Bytes per row, important in MIPS, important here
|
||||
unsigned char* pImg;
|
||||
@ -88,18 +89,19 @@ typedef struct
|
||||
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
|
||||
// Then in this "if" we basically set starting values for
|
||||
// everything we care about
|
||||
if (emptyImageInfo != NULL)
|
||||
{
|
||||
emptyImageInfo->imageWidth = 0;
|
||||
@ -134,6 +136,7 @@ void* freeResources(FILE* pFile, imageInfo* toFree)
|
||||
return freeImageInfo(toFree);
|
||||
}
|
||||
|
||||
|
||||
imageInfo* readBMP(const char* fileName)
|
||||
{
|
||||
imageInfo* pInfo = 0;
|
||||
@ -165,10 +168,10 @@ imageInfo* readBMP(const char* fileName)
|
||||
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);
|
||||
size_t returnedElements = fread( (void*)pInfo->pHeaderInfo,
|
||||
sizeof(bmpHeaderInfo),
|
||||
NUMBER_OF_HEADERS,
|
||||
bmpFile );
|
||||
|
||||
if (pInfo->pHeaderInfo == NULL || returnedElements != NUMBER_OF_HEADERS)
|
||||
{
|
||||
@ -224,6 +227,7 @@ imageInfo* readBMP(const char* fileName)
|
||||
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
|
||||
@ -249,56 +253,31 @@ int saveBMP(const imageInfo* pInfo, const char* fileName)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void set_pixel(imageInfo* pImg, unsigned int x, unsigned int y,
|
||||
unsigned int color)
|
||||
void set_pixel(unsigned char * pPix, 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
|
||||
}
|
||||
|
||||
*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)
|
||||
unsigned int getColor(unsigned char * pPix)
|
||||
{
|
||||
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);
|
||||
}
|
||||
char R, G, B; // change to unsigned char
|
||||
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)
|
||||
{
|
||||
@ -313,14 +292,18 @@ int calculateStartingPixelY(int pieceNumber, int horizontalDivisons,
|
||||
return (((pieceNumber - 1) / horizontalDivisons) * pieceHeight);
|
||||
}
|
||||
|
||||
extern void hello_world();
|
||||
extern void inner_loops(imageInfo* pInfo, int firstPiece, int pieceToSwapWith,
|
||||
int horizontalDivisions, int pieceWidth,
|
||||
int pieceHeight, int pieceWidthBytes, int bieceHeightBytes,
|
||||
unsigned int bytesPerRow,
|
||||
unsigned char *firstPieceStartingByte,
|
||||
unsigned char *secondPieceStartingByte); // Incomplete x86 solution
|
||||
|
||||
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)
|
||||
@ -328,71 +311,59 @@ int main(/*int argc, char* argv[]*/) // argc and argv[] are not used anywhere
|
||||
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;
|
||||
|
||||
int verticalDivisions, horizontalDivisions;
|
||||
printf(ENTER_VERTICAL_DIVISON_MESSAGE);
|
||||
scanf("%d", &verticalDivisions);
|
||||
printf(ENTER_HORIZONTAL_DIVISON_MESSAGE);
|
||||
scanf("%d", &horizontalDivisions);
|
||||
|
||||
int numberOfPieces = verticalDivisions * horizontalDivisions;
|
||||
int pieceWidth = (pInfo -> imageWidth) / horizontalDivisions;
|
||||
int pieceHeight = (pInfo -> imageHeight) / verticalDivisions;
|
||||
int pieceWidthBytes = pieceWidth * 3;
|
||||
int bieceHeightBytes = pieceHeight * (pInfo -> bytesPerRow);
|
||||
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);
|
||||
// hello_world(pInfo, firstPiece, pieceToSwapWith, horizontalDivisions,
|
||||
// pieceWidth, pieceHeight, pieceWidthBytes, bieceHeightBytes, pInfo -> bytesPerRow); // Incomplete x86 solution
|
||||
|
||||
int x = 0;
|
||||
for(x = 0; x < pieceWidth; x++)
|
||||
|
||||
|
||||
int firstPieceStartingX = calculateStartingPixelX(firstPiece, horizontalDivisions, pieceWidth);
|
||||
int firstPieceStartingY = calculateStartingPixelY(firstPiece, horizontalDivisions, pieceHeight);
|
||||
unsigned char *firstPieceStartingByte = firstPieceStartingX * 3 + firstPieceStartingY * pInfo -> bytesPerRow + pInfo -> pImg;
|
||||
|
||||
int secondPieceStartingX = calculateStartingPixelX(pieceToSwapWith, horizontalDivisions, pieceWidth);
|
||||
int secondPieceStartingY = calculateStartingPixelY(pieceToSwapWith, horizontalDivisions, pieceHeight);
|
||||
unsigned char *secondPieceStartingByte = secondPieceStartingX * 3 + secondPieceStartingY * pInfo -> bytesPerRow + pInfo -> pImg;
|
||||
|
||||
inner_loops(pInfo, firstPiece, pieceToSwapWith, horizontalDivisions,
|
||||
pieceWidth, pieceHeight, pieceWidthBytes, bieceHeightBytes, pInfo -> bytesPerRow, firstPieceStartingByte, secondPieceStartingByte);
|
||||
/* int x = 0;
|
||||
for(x = 0; x < pieceWidth * 3; x += 3)
|
||||
{
|
||||
int y = 0;
|
||||
for(y = 0; y < pieceHeight; y++)
|
||||
for(y = 0; y < pieceHeight * pInfo -> bytesPerRow; y += pInfo -> bytesPerRow)
|
||||
{
|
||||
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();
|
||||
|
||||
|
||||
unsigned int colorOne = getColor(secondPieceStartingByte + x + y);
|
||||
unsigned int colorTwo = getColor(firstPieceStartingByte + x + y);
|
||||
set_pixel(firstPieceStartingByte + x + y, colorOne);
|
||||
set_pixel(secondPieceStartingByte + x + y, colorTwo);
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
printf("JD\n");
|
||||
|
||||
saveBMP(pInfo, DESTINATION_IMAGE_NAME);
|
||||
|
||||
freeResources(NULL, pInfo);
|
||||
|
||||
// printf("Operation failed succesfully\n");
|
||||
return 0;
|
||||
}
|
||||
BIN
ECOAR/C/puzzle.o
Normal file
BIN
ECOAR/C/puzzle.out
Executable file
BIN
ECOAR/C/source.bmp
Executable file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Outputs/test1.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Outputs/test2.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Outputs/test3.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Outputs/test4.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Outputs/test5.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Outputs/test6.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Outputs/test7.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Outputs/test8.bmp
Normal file
|
After Width: | Height: | Size: 225 KiB |
BIN
ECOAR/C/tests/Sources/source1.bmp
Executable file
|
After Width: | Height: | Size: 225 KiB |
50
ECOAR/C/tests/testDescription.txt
Normal file
@ -0,0 +1,50 @@
|
||||
One of the easiest scenarios, divisable in both dimensions, both being same number and low number
|
||||
1. Input file : source1.bmp,
|
||||
Vertical Divisions: 2
|
||||
Horizontal Divisions: 2
|
||||
Result: test1.bmp
|
||||
|
||||
Both divisable and equal to 10 but higher number
|
||||
2. Input file : source1.bmp,
|
||||
Vertical Divisions: 10
|
||||
Horizontal Divisions: 10
|
||||
Result: test2.bmp
|
||||
|
||||
Low number, divisable, different
|
||||
3. Input file : source1.bmp,
|
||||
Vertical Divisions: 3
|
||||
Horizontal Divisions: 4
|
||||
Result: test3.bmp
|
||||
|
||||
Low number, not divisable, diffrent
|
||||
4. Input file : source1.bmp,
|
||||
Vertical Divisions: 4
|
||||
Horizontal Divisions: 3
|
||||
Result: test4.bmp
|
||||
|
||||
Very different number, divisable
|
||||
5. Input file : source1.bmp,
|
||||
Vertical Divisions: 2
|
||||
Horizontal Divisions: 20
|
||||
Result: test5.bmp
|
||||
|
||||
Very different number, divisable
|
||||
6. Input file : source1.bmp,
|
||||
Vertical Divisions: 20
|
||||
Horizontal Divisions: 2
|
||||
Result: test6.bmp
|
||||
|
||||
Highest number, different, non divisable
|
||||
7. Input file : source1.bmp,
|
||||
Vertical Divisions: 320
|
||||
Horizontal Divisions: 240
|
||||
Result: test7.bmp
|
||||
|
||||
Highest number, different, divisable
|
||||
8. Input file : source1.bmp,
|
||||
Vertical Divisions: 240
|
||||
Horizontal Divisions: 320
|
||||
Result: test8.bmp
|
||||
|
||||
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
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
|
||||
@ -1,27 +0,0 @@
|
||||
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
|
||||
@ -1,14 +0,0 @@
|
||||
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
|
||||
@ -1,727 +0,0 @@
|
||||
.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
|
||||