D.gnu - GDC 6.3.0 real mode wrong get array string
- jila (82/82) Apr 13 2017 Good afternoon, I decided to write the operating system loader on
Good afternoon, I decided to write the operating system loader on D. Build with - gdc-6.3.0+2.068.2-x86_64-linux-gnu - real mode 16bit, gdc –m16 I can not understand what happens when I access a char array extern (C) int _main() { string he="1234567890"; for (int i=0; i<he.length;i++) { char cc =he[i]; //print(cc); } } As a result, I get - 0,2,0,4,0,6,0,8,0 As you can see, non-even elements have zero. What can be wrong? --------------------- ld ---------------------------------- ENTRY(_main); SECTIONS { . = 0x7C00; .text : AT(0x7C00) { *(.text); } .data : { *(.data); *(.bss); *(.rodata); } .sig : AT(0x7DFE) { SHORT(0xaa55); } } --------------------- register ------------------- eax = 0x00000000 ecx = 0x00000000 edx = 0x0000009f ebx = 0x00000000 esp = 0x000007c0 ebp = 0x000003fc esi = 0x00000000 edi = 0x00000000 eip = 0x00007c20 cs = 0x000007c0 ss = 0x00000000 ds = 0x00000040 es = 0x00000000 fs = 0x00000000 gs = 0x00000000 eflags = 0x00000206 al = 0x00 cl = 0x00 dl = 0x9f bl = 0x00 ah = 0x00 ch = 0x00 dh = 0x00 bh = 0x00 ax = 0x0000 cx = 0x0000 dx = 0x009f bx = 0x0000 bp = 0x03fc si = 0x0000 di = 0x0000 --------------------- asm ------------------------- // address he ->0x8058 string he="1234567890"; 000x7c0e mov WORD PTR [di-0x20],0xa 000x7c15 add BYTE PTR [eax],al 000x7c17 mov WORD PTR [di-0x1c],0x8058 000x7c1e add BYTE PTR [eax],al for (int i=0; i<he.length;i++) 000x7c20 mov WORD PTR [di-0xc],0x0 000x7c27 add BYTE PTR [eax],al 000x7c29 mov dx,WORD PTR [di-0x20] 000x7c2e mov ax,WORD PTR [di-0xc] 000x7c33 cmp dx,ax 000x7c36 jbe 0x7c58 <_main+88> { char cc =he[i]; // dx <- address he - 0x8058 000x7c38 mov dx,WORD PTR [di-0x1c] // ax <- i 000x7c3d mov ax,WORD PTR [di-0xc] // ax <- he+i 000x7c42 add ax,dx // bx=0, si=0 000x7c45 movzx ax,BYTE PTR [bx+si] 000x7c4a mov BYTE PTR [di-0x11],al //print(cc); 000x7c50 add WORD PTR [di-0xc],0x1 000x7c56 jmp 0x7c29 <_main+41> }
Apr 13 2017