Sorry about that. I used 2 and it failed (though in
another program). Also the regular assignment failed
as well. (couldn't find it in your asm output)

OK: here's my code:
#include <sys.h>
#include <serial.h>
#include <rs232.h>
#include <string.h>
#include "printf.h"
#include "vt100.h"

struct unaligned {
        char first;
        int second;
} __attribute__((packed));

union test {
        struct unaligned data;
        char cdata[3];
};

void start_app() {
        union test test;
        int data, tmp;
        test.cdata[0] = 0x1;
        test.cdata[1] = 0x2;
        test.cdata[2] = 0x3;
        
        data = test.data.second;
        memcpy(&tmp, &test.data.second, 2);
        while (1) {
                printf("%x %x %x\r\n", test.data.second, data, tmp);
                sys_delay(100);
        }
}

This gives me the following asm:
 * Function `start_app' 
 ***********************/
start_app:
/* prologue: frame size = 4 */
.L__FrameSize_start_app=0x4
.L__FrameOffset_start_app=0x6
        push    r11
        sub     #4, r1  ;       4, fpn 0
/* prologue end (size=2) */
        mov.b   #llo(1), @r1
        mov.b   #llo(2), 1(r1)
        mov.b   #llo(3), 2(r1)
        mov     1(r1), r11 ; FAILS because not aligned
.L5:                       ; (is regular assignment)
        push    r11
        push    r11
        push    2+5(r1)
        push    #.LC0
        call    #printf
        mov     #llo(100), r15 
        call    #sys_delay
        add     #llo(8), r1
        jmp     .L5

I'm not sure where the memcpy went though

G Halkes
--- Dmitry <[email protected]> wrote:
> 
> oops...
> you should pass a copy size to memcpy() as third
> parameter.
> I passed 3.
> From the output I see everything is correct:
> main:
> /* prologue: frame size = 6 */
> .L__FrameSize_main=0x6
> .L__FrameOffset_main=0x6
>         mov     #(__stack-6), r1
> /* prologue end (size=2) */
> ;; allocate test structure on stack
>         mov.b   #llo(1), @r1     ;    load 0x01  
>         mov.b   #llo(2), 1(r1)   ;   load 2
>         mov.b   #llo(3), 2(r1)   ;  load 3
>         mov     r1, r15          ;    
>         add     #llo(4), r15     ;   prepare
> destination pointer
>         mov     r1, r14         ;  load r14 with a
> pointer to test.data
>         add     #llo(1), r14     ;   skip 'first' in
> test.data
>         mov.b   @r14+, 4(r1)     ;   copy this. 
>         mov.b   @r14+, 1(r15)    ;  three
>         mov.b   @r14+, 2(r15)    ;  times
> /* epilogue: frame size=6 */
>         add     #6, r1
>         br      #__stop_progExec__
> /* epilogue end (size=4) */
> /* function main size 23 (17) */
> 
> 
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

Reply via email to