I have this C++ code I'm trying to replicate in Assembly (68K):
int main()
{
int i=0;
char *string = "This is a string"
while(string[i]!=' ')
{
/.../
i++;
}
return 0;
}
I'm stuck on the string[i]!=0, indexing part of assembly. I need to CMP.B with a letter string[i] with some ' ' in memory. I tried CMP.B [STRING, D3],D5 with STRING being the string stored as a variable, D3 being the current index as a number stored in a register and D5 being the empty space I'm comparing it with in a register,
This won't work: You need to use an address register and you cannot use a 32-bit offset when using a register.
Instead, load the address of
STRINGinto an address register - for exampleA4:LEA.L (STRING), A4Then perform
CMP.B (0,D3,A4),D5EDIT
I don't know the assembler you are using. Using GNU assembler, the instruction
CMP.B (0,D3,A4),D5is writen asCMP.B (0,%D3,%A4),%D5.I just looked up the 68000 programmer's manual and it seems that the official syntax is: "
CMP.B (0,A4,D3.L),D5" (or "CMP.B (0,A4,D3.W),D5" if only the low 16 Bits ofD3shall be used).The instruction accesses the byte at the address
A4+D3, so if the registerA4contains the address ofstring[0](this means:A4contains the value of the pointerstring!) and the registerD3contains the valuei, the instruction accesses the valuestring[i].That value will be compared to the low 8 bits of
D5.