Smache 0 Posted February 20, 2006 Report Share Posted February 20, 2006 SourceBoost 6.31, BoostC, Windows XP #include <system.h> void main(void) { char* string; string="0123456789"; string="abcdefghij"; string="klmnopqrst"; while(1); } Asm output: string="0123456789";0003 3030 MOVLW 0x30 0004 1283 BCF STATUS, RP0 0005 1303 BCF STATUS, RP1 0006 00A0 MOVWF CompTempVar52 0007 3031 MOVLW 0x31 0008 00A1 MOVWF CompTempVar52+D'1' 0009 3032 MOVLW 0x32 000A 00A2 MOVWF CompTempVar52+D'2' 000B 3033 MOVLW 0x33 000C 00A3 MOVWF CompTempVar52+D'3' 000D 3034 MOVLW 0x34 000E 00A4 MOVWF CompTempVar52+D'4' 000F 3035 MOVLW 0x35 0010 00A5 MOVWF CompTempVar52+D'5' 0011 3036 MOVLW 0x36 0012 00A6 MOVWF CompTempVar52+D'6' 0013 3037 MOVLW 0x37 0014 00A7 MOVWF CompTempVar52+D'7' 0015 3038 MOVLW 0x38 0016 00A8 MOVWF CompTempVar52+D'8' 0017 3039 MOVLW 0x39 0018 00A9 MOVWF CompTempVar52+D'9' 0019 01AA CLRF CompTempVar52+D'10' 001A 3000 MOVLW HIGH(CompTempVar52+D'0') 001B 00C2 MOVWF main_1_string+D'1' 001C 3020 MOVLW LOW(CompTempVar52+D'0') 001D 00C1 MOVWF main_1_string string="abcdefghij"; 001E 3061 MOVLW 0x61 001F 00AB MOVWF CompTempVar53 0020 3062 MOVLW 0x62 0021 00AC MOVWF CompTempVar53+D'1' 0022 3063 MOVLW 0x63 0023 00AD MOVWF CompTempVar53+D'2' 0024 3064 MOVLW 0x64 0025 00AE MOVWF CompTempVar53+D'3' 0026 3065 MOVLW 0x65 0027 00AF MOVWF CompTempVar53+D'4' 0028 3066 MOVLW 0x66 0029 00B0 MOVWF CompTempVar53+D'5' 002A 3067 MOVLW 0x67 002B 00B1 MOVWF CompTempVar53+D'6' 002C 3068 MOVLW 0x68 002D 00B2 MOVWF CompTempVar53+D'7' 002E 3069 MOVLW 0x69 002F 00B3 MOVWF CompTempVar53+D'8' 0030 306A MOVLW 0x6A 0031 00B4 MOVWF CompTempVar53+D'9' 0032 01B5 CLRF CompTempVar53+D'10' 0033 3000 MOVLW HIGH(CompTempVar53+D'0') 0034 00C2 MOVWF main_1_string+D'1' 0035 302B MOVLW LOW(CompTempVar53+D'0') 0036 00C1 MOVWF main_1_string string="klmnopqrst"; 0037 306B MOVLW 0x6B 0038 00B6 MOVWF CompTempVar54 0039 306C MOVLW 0x6C 003A 00B7 MOVWF CompTempVar54+D'1' 003B 306D MOVLW 0x6D 003C 00B8 MOVWF CompTempVar54+D'2' 003D 306E MOVLW 0x6E 003E 00B9 MOVWF CompTempVar54+D'3' 003F 306F MOVLW 0x6F 0040 00BA MOVWF CompTempVar54+D'4' 0041 3070 MOVLW 0x70 0042 00BB MOVWF CompTempVar54+D'5' 0043 3071 MOVLW 0x71 0044 00BC MOVWF CompTempVar54+D'6' 0045 3072 MOVLW 0x72 0046 00BD MOVWF CompTempVar54+D'7' 0047 3073 MOVLW 0x73 0048 00BE MOVWF CompTempVar54+D'8' 0049 3074 MOVLW 0x74 004A 00BF MOVWF CompTempVar54+D'9' 004B 01C0 CLRF CompTempVar54+D'10' 004C 3000 MOVLW HIGH(CompTempVar54+D'0') 004D 00C2 MOVWF main_1_string+D'1' 004E 3036 MOVLW LOW(CompTempVar54+D'0') 004F 00C1 MOVWF main_1_string Memory Usage Report=================== RAM available:256 bytes, used:35 bytes (13.7%), free:221 bytes (86.3%), Heap size:221 bytes, Heap max single alloc:95 bytes ROM available:4096 words, used:84 words (2.1%), free:4012 words (97.9%) Why different temporary strings (CompTempVar52, CompTempVar53, CompTempVar54) for the same string variable? Quote Link to post Share on other sites
carolyn 0 Posted February 20, 2006 Report Share Posted February 20, 2006 Smache, This is standard C char pointer assignment all compilers work this way. Try creating an array or allocating space for the string and use strcpy this should reduce the ram usage. Carolyn Quote Link to post Share on other sites
Pavel 0 Posted February 21, 2006 Report Share Posted February 21, 2006 ... Why different temporary strings (CompTempVar52, CompTempVar53, CompTempVar54) for the same string variable? For each expression like 'str = "abc"' compiler creates a temporary char array where it stores the value of the string from the right side of such expression. Than it assignes address of this array to the pointer from the left side of the expression. These temporary strings have the lifetime till the end of the current scope. That's why for such string from your sample a new temp variable is used. Regards, Pavel Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.