Why is it that compilers never start offsetting from index zero of the base pointer, see here:
! 1
! 1 # 1 "test.c"
! 1 struct test{
! 2 int a;
!BCC_EOS
! 3 int b;
!BCC_EOS
! 4 };
!BCC_EOS
! 5
! 6 int main()
! 7 {
export _main
_main:
! 8 int a;
!BCC_EOS
! 9 char array[5];
!BCC_EOS
! 10 array[a] = 10;
push bp
mov bp,sp
push di
push si
add sp,*-8
! Debug: ptradd int a = [S+$E-8] to [5] char array = S+$E-$D (used reg = )
mov ax,-6[bp]
mov bx,bp
add bx,ax
! Debug: eq int = const $A to char = [bx-$B] (used reg = )
mov al,*$A
mov -$B[bx],al
!BCC_EOS
! 11 return array[a];
! Debug: ptradd int a = [S+$E-8] to [5] char array = S+$E-$D (used reg = )
mov ax,-6[bp]
mov bx,bp
add bx,ax
! Debug: cast int = const 0 to char = [bx-$B] (used reg = )
mov al,-$B[bx]
xor ah,ah
add sp,*8
pop si
pop di
pop bp
ret
!BCC_EOS
! 12
! 13 }
! 14
! Register BX used in function main
I am writing my own compiler and don't want to be the unfortunate one to make a mistake if their is a reason to it.
Also how is the code generated above even safe to use as the BX register defaults to the data segment, which shouldn't be pointing at the stack anyway.