Compare array subscript operations with the speed of pointer operation (convert the program into assembler)

xiaoxiao2021-03-06  51

I saw the post of the relationship between Kaikai compared, I used the file conversion method to see the editor if the compiler, the result is true than the array. Convert the following program to assemble file comparison loop operation, discovering less cycle comparison group, so the pointer is faster main () {Int Array [10]; int * p; int 1;

For (i = 0; i <10; i ) array [i] = 1; for (p = array; p

ifndef ?? version debug macro endm endif debug S "mmm.c" _TEXT segment byte public 'CODE'DGROUP group _DATA, _BSS assume cs: _TEXT, ds: DGROUP, ss: DGROUP_TEXT ends_DATA segment word public'?? DATA'd @ label byted @ w label word_DATA ends_BSS segment word public 'BSS'b @ label byteb @ w label word debug C E9565D9131056D6D6D2E63_BSS ends_TEXT segment byte public?' CODE ';? debug L 1_main proc near push bp mov bp, sp sub sp, 20 push Si Push Di;? Debug L 7

; ------------------------------------------------- ----------- The process of array assignment XOR DI, DI; counter Qing 0 JMP Short @ 5 @ 4 :;? Debug L 8 MOV BX, DI; assign the counter to BX SHL BX, 1 Offset address mobile two LEA AX, Word PTR [BP-20]; acquired array offset address add bx, ax; get the specific address MOV Word PTR [BX], 1; assignment @ 3: Inc Di; counter plus 1 @ 5: CMP DI, 10; Judgment is less than 10 JL @ 4; ---------------------------------- ---------------------------- @ 2 :;? Debug L 9; ------------- -------------------------------------; Pointer assignment process Lea Si, Word PTR [BP-20]; acquired array offset address JMP Short @ 9

@ 8:? Debug L 10 MOV WORD PTR [Si], 2; Getting to Guide @ 7: Inc Si Inc Si @ 9:; Judging whether it is less than the array last address Lea AX, Word PTR [BP] CMP AX, Si Ja @8;----------------------------------------------- ---------------

转载请注明原文地址:https://www.9cbs.com/read-79710.html

New Post(0)