Papero
Wednesday 16 April 2008 - 17:33
CITAZIONE (orochimaru 91 @ Wednesday 16 April 2008 - 15:11)

E come si fa ? Grazie .............

...................... Qualcosa capisco.............
studio assembler a scuola
Studi l'ARM assembly a scuola?

Comunque: per ottenere il codice asm ti serve un debugger. Il codice asm che otterrai NON è come quello che scriverebbe un uomo, ma è quello generato dal compilatore, che è oltremodo ingarbugliato, a causa di ottimizzazioni, comportamenti anomali del generatore di asm e sostituzione di labels.
Ti faccio un esempio per farti capire. Mettiamo che voglio scrivere un programmino in C che mi metta sullo schermo un pixel rosso. Il listato sarebbe questo:
CODICE
#define DISPLAY_CR (*(volatile unsigned int *) 0x4000000)
#define SUB_DISPLAY_CR (*(volatile unsigned int *) 0x4001000)
#define VRAM_A ((unsigned short int *) 0x6800000)
#define VRAM_A_CR (*(volatile unsigned char *) 0x04000240)
#define VRAM_ENABLE (1 << 7)
int main(void) {
DISPLAY_CR = 0x00020000;
VRAM_A_CR = VRAM_ENABLE | 0;
VRAM_A[24450] = 0x001f;
while (1) {
}
return 0;
}
Il codice ASM generato dal compilatore per questo microscopico programmino è questo:
CODICE
.code 16
.file "main.cpp"
.section .debug_abbrev,"",%progbits
.Ldebug_abbrev0:
.section .debug_info,"",%progbits
.Ldebug_info0:
.section .debug_line,"",%progbits
.Ldebug_line0:
.text
.Ltext0:
.align 2
.global main
.code 16
.thumb_func
.type main, %function
main:
.LFB2:
.file 1 "d:/devkitPro/examples/nds/Graphics/2D/asm/source/main.cpp"
.loc 1 39 0
push {lr}
.LCFI0:
.loc 1 42 0
mov r2, #128
mov r3, #128
lsl r2, r2, #19
lsl r3, r3, #10
str r3, [r2]
.loc 1 43 0
ldr r2, .L5
mov r3, #128
neg r3, r3
strb r3, [r2]
.loc 1 44 0
ldr r3, .L5+4
mov r2, #31
strh r2, [r3]
.L2:
b .L2
.L6:
.align 2
.L5:
.word 67109440
.word 109100804
.LFE2:
.size main, .-main
.section .debug_frame,"",%progbits
.Lframe0:
.4byte .LECIE0-.LSCIE0
.LSCIE0:
.4byte 0xffffffff
.byte 0x1
.ascii "\000"
.uleb128 0x1
.sleb128 -4
.byte 0xe
.byte 0xc
.uleb128 0xd
.uleb128 0x0
.align 2
.LECIE0:
.LSFDE0:
.4byte .LEFDE0-.LASFDE0
.LASFDE0:
.4byte .Lframe0
.4byte .LFB2
.4byte .LFE2-.LFB2
.byte 0x4
.4byte .LCFI0-.LFB2
.byte 0xe
.uleb128 0x4
.byte 0x8e
.uleb128 0x1
.align 2
.LEFDE0:
.text
.Letext0:
.section .debug_loc,"",%progbits
.Ldebug_loc0:
.LLST0:
.4byte .LFB2-.Ltext0
.4byte .LCFI0-.Ltext0
.2byte 0x1
.byte 0x5d
.4byte .LCFI0-.Ltext0
.4byte .LFE2-.Ltext0
.2byte 0x2
.byte 0x7d
.sleb128 4
.4byte 0x0
.4byte 0x0
.section .debug_info
.4byte 0x41
.2byte 0x2
.4byte .Ldebug_abbrev0
.byte 0x4
.uleb128 0x1
.4byte .Ldebug_line0
.4byte .Letext0
.4byte .Ltext0
.4byte .LASF0
.byte 0x4
.4byte .LASF1
.4byte .LASF2
.uleb128 0x2
.byte 0x1
.4byte .LASF3
.byte 0x1
.byte 0x27
.4byte 0x3d
.4byte .LFB2
.4byte .LFE2
.4byte .LLST0
.uleb128 0x3
.ascii "int\000"
.byte 0x4
.byte 0x5
.byte 0x0
.section .debug_abbrev
.uleb128 0x1
.uleb128 0x11
.byte 0x1
.uleb128 0x10
.uleb128 0x6
.uleb128 0x12
.uleb128 0x1
.uleb128 0x11
.uleb128 0x1
.uleb128 0x25
.uleb128 0xe
.uleb128 0x13
.uleb128 0xb
.uleb128 0x3
.uleb128 0xe
.uleb128 0x1b
.uleb128 0xe
.byte 0x0
.byte 0x0
.uleb128 0x2
.uleb128 0x2e
.byte 0x0
.uleb128 0x3f
.uleb128 0xc
.uleb128 0x3
.uleb128 0xe
.uleb128 0x3a
.uleb128 0xb
.uleb128 0x3b
.uleb128 0xb
.uleb128 0x49
.uleb128 0x13
.uleb128 0x11
.uleb128 0x1
.uleb128 0x12
.uleb128 0x1
.uleb128 0x40
.uleb128 0x6
.byte 0x0
.byte 0x0
.uleb128 0x3
.uleb128 0x24
.byte 0x0
.uleb128 0x3
.uleb128 0x8
.uleb128 0xb
.uleb128 0xb
.uleb128 0x3e
.uleb128 0xb
.byte 0x0
.byte 0x0
.byte 0x0
.section .debug_pubnames,"",%progbits
.4byte 0x17
.2byte 0x2
.4byte .Ldebug_info0
.4byte 0x45
.4byte 0x25
.ascii "main\000"
.4byte 0x0
.section .debug_aranges,"",%progbits
.4byte 0x1c
.2byte 0x2
.4byte .Ldebug_info0
.byte 0x4
.byte 0x0
.2byte 0x0
.2byte 0x0
.4byte .Ltext0
.4byte .Letext0-.Ltext0
.4byte 0x0
.4byte 0x0
.section .debug_str,"MS",%progbits,1
.LASF1:
.ascii "d:/devkitPro/examples/nds/Graphics/2D/asm/source/ma"
.ascii "in.cpp\000"
.LASF2:
.ascii "d:\\devkitPro\\examples\\nds\\Graphics\\2D\\asm\\bu"
.ascii "ild\000"
.LASF0:
.ascii "GNU C++ 4.1.2 (devkitARM release 21)\000"
.LASF3:
.ascii "main\000"
.ident "GCC: (GNU) 4.1.2 (devkitARM release 21)"
Ecco. Adesso immagina che cavolo potrà mai venire fuori da un gioco come Pokemon e mettiti l'anima in pace.