I figured that is what it was looking for. Thank you for all of the help. One last thing, could explain what dl is? I thought there were only 9 32 bit registers(eax,ebx,ecx,edx)-> General Purpose (esi,edi,eip,esp,ebp)->specialty
17 Replies - 1789 Views - Last Post: 11 April 2012 - 07:19 PM
#16
Re: Inline Gnu Assembly, Looping Multi-Dimensional Array
Posted 11 April 2012 - 07:01 PM
#17
Re: Inline Gnu Assembly, Looping Multi-Dimensional Array
Posted 11 April 2012 - 07:04 PM
Each register is broken down to WORD/HIBYTE, LOWBYTE
#18
Re: Inline Gnu Assembly, Looping Multi-Dimensional Array
Posted 11 April 2012 - 07:19 PM
Thanks a bunch man. In case you were curious to see, here is my finished prgrm. It evaluates a GO board inputted from a text file:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
FILE *inputFilePtr;
char board[7][7];
int blkCount = 0, whtCount = 0;
void usage() {
printf("usage: one filename argument.\n");
}
void read_board() {
int i, j;
for (i=0; i != 7; i++) {
for (j=0; j != 7; j++) {
fscanf(inputFilePtr, "%c", &board[i][j]);
}
fscanf(inputFilePtr, "\n");
}
}
bool checkDir(int x, int y, char c){
if(x != 6 && board[x+1][y] == c) return true;
else if(y != 6 && board[x][y+1] == c) return true;
else if(x != 0 && board[x-1][y] == c) return true;
else if(y != 0 && board[x][y-1] == c) return true;
else return false;
}
bool containsDots(){
int i,j;
for(j = 0; j < 7; j++){
for(i = 0; i < 7; i++){
if(board[i][j] == '.') return true;
}
}
return false;
}
void validityCheck(int i, int j){
if(board[i][j] == '@' && checkDir(i,j,'#')) board[i][j]='n';
if(board[i][j] == '#' && checkDir(i,j,'@')) board[i][j]='n';
if(board[i][j] == '#' && checkDir(i,j,'n') ||
board[i][j] == '@' && checkDir(i,j,'n')) board[i][j]='n';
}
void parse(){
int x,j=0,i=0;
for(j = 0; j < 7; j++){
for(i = 0; i < 7; i++){
validityCheck(i,j);
if(board[i][j] == '.'){
if(checkDir(i,j,'b') && checkDir(i,j,'w')) board[i][j]='n';
else if(checkDir(i,j,'n')) board[i][j]='n';
else if(checkDir(i,j,'b') && !checkDir(i,j,'w')) board[i][j]='@';
else if(!checkDir(i,j,'b') && checkDir(i,j,'w')) board[i][j]='#';
else if(checkDir(i,j, '#') && !checkDir(i,j,'b')
&& !checkDir(i,j,'w')) board[i][j] = '#';
else if(checkDir(i,j, '@') && !checkDir(i,j,'b')
&& !checkDir(i,j,'w')) board[i][j] = '@';
}
}
}
}
void count() {
__asm__("\
xorl %eax, %eax\n\
xorl %ebx, %ebx\n\
xorl %ecx, %ecx\n\
xorl %edx, %edx\n\
CharCount:\n\
movb board(,%ecx,1), %dl\n\
cmpb $64, %dl\n\
je AddBlk\n\
cmpb $35, %dl\n\
je AddWht\n\
NextChar:\n\
incl %ecx\n\
cmpl $49, %ecx\n\
jne CharCount\n\
jmp LoopDone\n\
AddBlk:\n\
incl %eax\n\
jmp NextChar\n\
AddWht:\n\
incl %ebx\n\
jmp NextChar\n\
LoopDone:\n\
movl %eax, blkCount\n\
movl %ebx, whtCount\n\
");
}
void print_results() {
printf("black:%d\nwhite:%d\n", blkCount, whtCount);
}
int main(int argc, char**argv) {
if (argc != 2) {
usage();
return 1;
}
inputFilePtr = fopen(argv[1], "r");
if (inputFilePtr == NULL) {
printf("Couldn't open file, %s\n", argv[1]);
return 1;
}
read_board();
while(containsDots()){
int i;
for(i = 0; i < 10; i++) parse();
}
count();
print_results();
return 0;
}
This post has been edited by raspinudo: 11 April 2012 - 07:20 PM
|
|

New Topic/Question
Reply



MultiQuote





|