-
-
Save beroset/4ab0eb7c4a85678dfb2296c164014798 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void loop_up() { | |
int i; | |
for (i = 0; i < 42; ++i) { | |
printf("Hello"); | |
} | |
} | |
void loop_down() { | |
int i; | |
for (i = 42; i; --i) { | |
printf("Hello"); | |
} | |
} | |
/* using sdcc version 3.6.0 | |
* (http://sdcc.sourceforge.net/) with 8051 target: | |
* command line: sdcc -S --std-sdcc99 -mmcs51 --opt-code-speed loop_comparison.c | |
*/ | |
/* resulting assembly (partial): */ | |
/* | |
;------------------------------------------------------------ | |
; loop_comparison.c:3: void loop_up() { | |
; ----------------------------------------- | |
; function loop_up | |
; ----------------------------------------- | |
_loop_up: | |
ar7 = 0x07 | |
ar6 = 0x06 | |
ar5 = 0x05 | |
ar4 = 0x04 | |
ar3 = 0x03 | |
ar2 = 0x02 | |
ar1 = 0x01 | |
ar0 = 0x00 | |
; loop_comparison.c:5: for (i = 0; i < 42; ++i) { | |
mov r6,#0x00 | |
mov r7,#0x00 | |
00102$: | |
; loop_comparison.c:6: printf("Hello"); | |
push ar7 | |
push ar6 | |
mov a,#___str_0 | |
push acc | |
mov a,#(___str_0 >> 8) | |
push acc | |
mov a,#0x80 | |
push acc | |
lcall _printf | |
dec sp | |
dec sp | |
dec sp | |
pop ar6 | |
pop ar7 | |
; loop_comparison.c:5: for (i = 0; i < 42; ++i) { | |
inc r6 | |
cjne r6,#0x00,00110$ | |
inc r7 | |
00110$: | |
clr c | |
mov a,r6 | |
subb a,#0x2a | |
mov a,r7 | |
xrl a,#0x80 | |
subb a,#0x80 | |
jc 00102$ | |
ret | |
;------------------------------------------------------------ | |
;Allocation info for local variables in function 'loop_down' | |
;------------------------------------------------------------ | |
;i Allocated to registers r6 r7 | |
;------------------------------------------------------------ | |
; loop_comparison.c:10: void loop_down() { | |
; ----------------------------------------- | |
; function loop_down | |
; ----------------------------------------- | |
_loop_down: | |
; loop_comparison.c:12: for (i = 42; i; --i) { | |
mov r6,#0x2a | |
mov r7,#0x00 | |
00102$: | |
; loop_comparison.c:13: printf("Hello"); | |
push ar7 | |
push ar6 | |
mov a,#___str_0 | |
push acc | |
mov a,#(___str_0 >> 8) | |
push acc | |
mov a,#0x80 | |
push acc | |
lcall _printf | |
dec sp | |
dec sp | |
dec sp | |
pop ar6 | |
pop ar7 | |
; loop_comparison.c:12: for (i = 42; i; --i) { | |
mov a,r6 | |
add a,#0xff | |
mov r4,a | |
mov a,r7 | |
addc a,#0xff | |
mov r5,a | |
mov ar6,r4 | |
mov ar7,r5 | |
mov a,r4 | |
orl a,r5 | |
jnz 00102$ | |
ret | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment