PTR error and OFFSET going from C to assembler

261 views Asked by At

I have a function in C performed as follows

 int  rowScreen;  
 int  colScreen;  
 char charac;      
 char tiles[DimMatrix][DimMatrix] = { {'1','2','4'},
                                    {'6','8','A'},                                     
                                    {'C','E',' '} };
void updateBoardP1_C(){
int i, j;
rowScreen = 12;
for (i=0;i<DimMatrix;i++){
  colScreen = 8;
  for (j=0;j<DimMatrix;j++){
     gotoxyP1_C();
     charac = tiles[i][j];
     printchP1_C();
     colScreen = colScreen + 4;
  }
  rowScreen = rowScreen + 2;
 }
 rowScreen = 8;
 colScreen = 20;
 gotoxyP1_C(0);
 charac = moves;
 charac = charac + '0';
 printchP1_C();
}

I change it to assembler and it looks like the following

updateBoardP1_C:
    push    rbp
    mov     rbp, rsp
    sub     rsp, 16
    mov     DWORD PTR rowScreen[rip], 12
    mov     DWORD PTR [rbp-4], 0
    jmp     .L2
.L5:
    mov     DWORD PTR colScreen[rip], 8
    mov     DWORD PTR [rbp-8], 0
    jmp     .L3
.L4:
    mov     eax, 0
    call    gotoxyP1_C
    mov     eax, DWORD PTR [rbp-8]
    movsx   rcx, eax
    mov     eax, DWORD PTR [rbp-4]
    movsx   rdx, eax
    mov     rax, rdx
    add     rax, rax
    add     rax, rdx
    add     rax, rcx
    add     rax, OFFSET FLAT:tiles
    movzx   eax, BYTE PTR [rax]
    mov     BYTE PTR charac[rip], al
    mov     eax, 0
    call    printchP1_C
    mov     eax, DWORD PTR colScreen[rip]
    add     eax, 4
    mov     DWORD PTR colScreen[rip], eax
    add     DWORD PTR [rbp-8], 1
.L3:
    cmp     DWORD PTR [rbp-8], 2
    jle     .L4
    mov     eax, DWORD PTR rowScreen[rip]
    add     eax, 2
    mov     DWORD PTR rowScreen[rip], eax
    add     DWORD PTR [rbp-4], 1
.L2:
    cmp     DWORD PTR [rbp-4], 2
    jle     .L5
    mov     DWORD PTR rowScreen[rip], 8
    mov     DWORD PTR colScreen[rip], 20
    mov     edi, 0
    mov     eax, 0
    call    gotoxyP1_C
    mov     eax, DWORD PTR moves[rip]
    mov     BYTE PTR charac[rip], al
    movzx   eax, BYTE PTR charac[rip]
    add     eax, 48
    mov     BYTE PTR charac[rip], al
    mov     eax, 0
    call    printchP1_C
    nop
    leave
    ret

When wanting to execute this assembly code in 64-bit linux with yasm with this:

yasm -f elf64 -g dwartf2 P1TOC.asm 

throws me the following errors and I don't know how to fix them.

undefined symbol 'PTR'
undefined symbol 'OFFSET'

Is there a way to do the assembly code without PTR and OFFSET? What am I doing wrong?

0

There are 0 answers