Home > Enterprise >  Use a single character for use in a comparison statement - Assembly (Motorola 68k)
Use a single character for use in a comparison statement - Assembly (Motorola 68k)

Time:04-10

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,

CodePudding user response:

CMP.B [STRING, D3],D5

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 STRING into an address register - for example A4:

LEA.L (STRING), A4

Then perform CMP.B (0,D3,A4),D5

EDIT

I don't know the assembler you are using. Using GNU assembler, the instruction CMP.B (0,D3,A4),D5 is writen as CMP.B (0,

  • Related