I need to make a C++ program for an assignment that can add or subtract 1024 and 2048 bit binary numbers, and the functions that do said operations must be made in Assembly. I tried going about this by interpreting the numbers as 64-long arrays of 32 bit binary numbers and adding them one element after another, starting from the end, and writing the result into the third array. However, after making a testing version made for arrays with only 3 32 bit numbers each, I'm faced with the fact that the function doesn't respond. I tried making a version of said function that works predetermined data, but the FASM compiler says "error: reserved word used as symbol.". There isn't an answer I could find anywhere, so now I'm asking for help here.
section '.data' data readable writable
IN_NUM1 dd 0b00000100000000000000000000000000, 0b00000100000000000000000000000000, 0b00000111111111111111111111111111 ;"error: reserved word used as symbol" is here
IN_NUM2 dd 0b00000010000000000000000000000000, 0b00000010000000000000000000000000, 0b00000100000000000000000000000000
OUT_NUM dd 0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 0b00000000000000000000000000000000
section '.code' code readable writable executable
start:
mov edi, [IN_NUM1]
mov esi, [IN_NUM2]
mov ecx, 3
PUSHING:
mov eax, [edi]
push eax
mov eax, [esi]
push eax
inc edi
inc esi
loop PUSHING
clc
ADDING:
pop eax
pop ebx
adc eax, ebx
mov [OUT_NUM+ecx-1], eax
loop ADDING
ccall [printf], [OUT_NUM]
ccall [getchar]
stdcall [ExitProcess],0
The error message from that line in a file by itself (editor's note: from my computer, not the OP's):
flat assembler version 1.73.24 (16384 kilobytes memory, x64)
foo.asm [1]:
IN_NUM1 dd 0b00000100000000000000000000000000, 0b00000100000000000000000000000000, 0b00000111111111111111111111111111 ;"error: reserved word used as symbol" is here
processed: IN_NUM1 dd 0b00000100000000000000000000000000,0b00000100000000000000000000000000,0b00000111111111111111111111111111
error: reserved word used as symbol.
But IN_NUM1 dd 1,2,4
assembles fine.
Author's edit: Thanks to the help of @PeterCordes, I have made good progress. However, there are still some issues. With the new code, the addition goes like this: 87654321 + 00000000, FFFFFFFF + 00000001, 04000000 + 02000000. And if I don't multiply ecx by 4, it goes "00000012 + 00000087, 00001234 + 00008765, 00123456 + 00876543". I don't get why this happens, and I would very much appreciate your help. And as for the code itself:
section '.data' data readable writable
IN_NUM1 dd 0x12345678, 0x04000000, 0xFFFFFFFF
IN_NUM2 dd 0x87654321, 0x02000000, 0x00000001
OUT_NUM dd 0x00000000, 0x00000000, 0x00000000
section '.code' code readable writable executable
start:
mov ecx, 3
clc
ADDING:
mov eax, [IN_NUM1+ecx*4]
mov ebx, [IN_NUM2+ecx*4]
adc eax, ebx
mov [OUT_NUM+ecx*4], eax
loop ADDING