fiveworlds Posted July 10, 2017 Posted July 10, 2017 Does anybody know how to use int arrays in the inline assembly compiler for c? I tried just putting the line[index] in but that gives me a "\n" access error. #include<stdio.h> #include<conio.h> #include<stdlib.h> int i; int line[38]; int repeatedNumbers[38]; int input; int loopcount; const LAST_LINE_DATABASE = "lastline.txt"; int main(int argc, char **argv) { filed(); _getch(); exit(EXIT_SUCCESS); } int filed() { // We assume argv[1] is a filename to open FILE *file = fopen("lastline.txt", "rb"); if (file == 0) { printf("Could not open file\n"); file = fopen(LAST_LINE_DATABASE, "wb"); for (i = 0; i < 38; i = i + 1) {line[i] = 1;} input = rand() % 36; repeatedNumbers[0] = input; line[input + 1] = 0; fwrite(line, sizeof(int), 38, file); return 1; } else { printf("File opened\n"); fread(line, sizeof(int), 38, file); for (i = 0; i < 38; i = i + 1) { printf("%d", line[i]); } fclose(file); return 0; } }
Sensei Posted July 10, 2017 Posted July 10, 2017 (edited) Your example does not want to compile on my Visual Studio Express, I had to add two lines: const char *LAST_LINE_DATABASE = "lastline.txt"; int filed(); Did you read MSDN entire section about inline assembly.. ? https://msdn.microsoft.com/en-us/library/4ks26t93.aspx That should be for a start. Here https://msdn.microsoft.com/en-us/library/bf1dw62z(v=vs.140).aspx they're showing code: __asm mov array[6], bx ; Store BX at array+6 (not scaled) __asm mov array[6 * TYPE int], 0 ; Store 0 at array + 24 But it's always constant index, in your case it's variable.. ? In old times, around '80-'90, we were used to take variable (address of structure/array) to one register, then take another variable to other register, multiply it by size of structure/array entry, and add together to get final address. final_addr = addr+size*index Edited July 10, 2017 by Sensei
fiveworlds Posted July 11, 2017 Author Posted July 11, 2017 Ah I was missing the type. It should be a variable yeah which should be helpful if I can get it working right. #include<stdio.h> #include<conio.h> #include<stdlib.h> int i; int k; int line[38]; int repeatedNumbers[38]; int input; int loopcount; int repeatsx[20]; int repeatsy[20]; int p = 0; const LAST_LINE_DATABASE = "lastline.txt"; int main(int argc, char **argv) { filed(); _getch(); exit(EXIT_SUCCESS); } int incrementLine() { _asm { ADD line[TYPE line * 0], 1; ADD line[TYPE line * 1], 1; ADD line[TYPE line * 2], 1; ADD line[TYPE line * 3], 1; ADD line[TYPE line * 4], 1; ADD line[TYPE line * 5], 1; ADD line[TYPE line * 6], 1; ADD line[TYPE line * 7], 1; ADD line[TYPE line * 8], 1; ADD line[TYPE line * 9], 1; ADD line[TYPE line * 10], 1; ADD line[TYPE line * 11], 1; ADD line[TYPE line * 12], 1; ADD line[TYPE line * 13], 1; ADD line[TYPE line * 14], 1; ADD line[TYPE line * 15], 1; ADD line[TYPE line * 16], 1; ADD line[TYPE line * 17], 1; ADD line[TYPE line * 18], 1; ADD line[TYPE line * 19], 1; ADD line[TYPE line * 20], 1; ADD line[TYPE line * 21], 1; ADD line[TYPE line * 22], 1; ADD line[TYPE line * 23], 1; ADD line[TYPE line * 24], 1; ADD line[TYPE line * 25], 1; ADD line[TYPE line * 26], 1; ADD line[TYPE line * 27], 1; ADD line[TYPE line * 28], 1; ADD line[TYPE line * 29], 1; ADD line[TYPE line * 30], 1; ADD line[TYPE line * 31], 1; ADD line[TYPE line * 32], 1; ADD line[TYPE line * 33], 1; ADD line[TYPE line * 34], 1; ADD line[TYPE line * 35], 1; ADD line[TYPE line * 36], 1; ADD line[TYPE line * 37], 1; } return 1; } int initLine() { _asm { MOV line[TYPE line * 0], 1; MOV line[TYPE line * 1], 1; MOV line[TYPE line * 2], 1; MOV line[TYPE line * 3], 1; MOV line[TYPE line * 4], 1; MOV line[TYPE line * 5], 1; MOV line[TYPE line * 6], 1; MOV line[TYPE line * 7], 1; MOV line[TYPE line * 8], 1; MOV line[TYPE line * 9], 1; MOV line[TYPE line * 10], 1; MOV line[TYPE line * 11], 1; MOV line[TYPE line * 12], 1; MOV line[TYPE line * 13], 1; MOV line[TYPE line * 14], 1; MOV line[TYPE line * 15], 1; MOV line[TYPE line * 16], 1; MOV line[TYPE line * 17], 1; MOV line[TYPE line * 18], 1; MOV line[TYPE line * 19], 1; MOV line[TYPE line * 20], 1; MOV line[TYPE line * 21], 1; MOV line[TYPE line * 22], 1; MOV line[TYPE line * 23], 1; MOV line[TYPE line * 24], 1; MOV line[TYPE line * 25], 1; MOV line[TYPE line * 26], 1; MOV line[TYPE line * 27], 1; MOV line[TYPE line * 28], 1; MOV line[TYPE line * 29], 1; MOV line[TYPE line * 30], 1; MOV line[TYPE line * 31], 1; MOV line[TYPE line * 32], 1; MOV line[TYPE line * 33], 1; MOV line[TYPE line * 34], 1; MOV line[TYPE line * 35], 1; MOV line[TYPE line * 36], 1; MOV line[TYPE line * 37], 1; } return 1; } int filed() { // We assume argv[1] is a filename to open FILE *file = fopen(LAST_LINE_DATABASE, "rb"); if (file == 0) { printf("Could not open file\n"); file = fopen(LAST_LINE_DATABASE, "wb"); input = rand() % 36; repeatedNumbers[0] = input; initLine(); line[input + 1] = 0; fwrite(line, sizeof(int), 38, file); loopcount = 1; } else { printf("File opened\n"); fread(line, sizeof(int), 38, file); for (i = 0; i < 38; i = i + 1) { printf("%d ", line[i]); } fclose(file); loopcount = 0; } fclose(file); file = fopen("data.txt", "wb+"); for (i = 0; i < 100 - loopcount; i++) { incrementLine(); input = rand() % 36; int switcher = 0; for (k = 0; k < sizeof(repeatedNumbers); k++) { if (repeatedNumbers[k] == input) { repeatsx[p] = input; repeatsy[p] = i; p = p + 1; switcher = 1; break; } } if (switcher == 0) { repeatedNumbers[sizeof(repeatedNumbers)] = input; } line[input + 1] = 0; if (100 - i < 37 - loopcount) { for (k = 0; k < 38; k = k + 1) { printf("%d ", line[k]); } } fwrite(line, sizeof(int), 38, file); } fclose(file); file = fopen(LAST_LINE_DATABASE, "wb"); fwrite(line, sizeof(int), 38, file); fclose(file); printf(","); for (i = 0; i < p - 1; i++) { printf("%d ",repeatsx[i]); printf("%d ", repeatsy[i]); } printf("%d ", repeatsx[p - 1]); printf("%d ", repeatsy[p - 1]); printf(","); for (k = 0; k < sizeof(repeatedNumbers); k++) { printf("%d ", repeatedNumbers[k]); } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now