这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » GCC GCC 在线汇编……

共3条 1/1 1 跳转至

GCC GCC 在线汇编……

院士
2006-09-17 18:14:16     打赏
GCC GCC 在线汇编……



关键词: 在线     汇编    

院士
2006-12-22 22:43:00     打赏
2楼
问 void
main(void)
{
    uint8_t c;
    c=test();
    for(;;);
}    
uint8_t
test(void)
{
    uint8_t value;
    asm volatile(
        "in %[value],_SREG_                \n\t"
        :[value] "=r"(value)
        :
        );
    return value;
}    
这是我写的一段在线汇编,编译时候老是出现
C:\WINDOWS\TEMP/ccvrjhgb.s:152: Error: constant value required
错误,并且也经常出现
test.c:26: warning: return type of `main' is not `int'
test.c:29: warning: implicit declaration of function `test'
test.c:35: warning: type mismatch with previous implicit declaration
test.c:35: warning: `test' was previously implicitly declared to return `int'这类警告,但是函数定义时候都有定义了函数的返回值了,类型也有说明了,还会出现这种警告?
1: test()要放到main()前面1、test()要放到main()前面
2、int main(void) 2: tczgg你好我是刚出道的,想学单片AVR汇编语言,以前在校学过51系列的,不知难不难,有空可否请教? 3: 老大,还是不行啊而且印象中GCC的函数顺序是没有严格要求的,还有,int了main函数,要return什么?? 4: 看一下我编译通过的代码typedef unsigned char uint8_t;

uint8_t test(void)
{
    uint8_t value;
    asm volatile(
        "in %[value],_SREG_  \n\t"
        :[value] "=r"(value)
        :
        );
    return value;
}    

int  main(void)
{
    uint8_t c;
    c=test();
    for(;;);
    return 0;
}    


编译生成的汇编码:
    .file    "aa.c"
    .arch atmega8
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
    .global __do_copy_data
    .global __do_clear_bss
    .text
.global    test
    .type    test, @function
test:
/* prologue: frame size=0 */
/* prologue end (size=0) */
/* #APP */
    in r24,_SREG_  
    
/* #NOAPP */
    clr r25
/* epilogue: frame size=0 */
    ret
/* epilogue end (size=1) */
/* function test size 6 (5) */
    .size    test, .-test
.global    main
    .type    main, @function
main:
/* prologue: frame size=0 */
    ldi r28,lo8(__stack - 0)
    ldi r29,hi8(__stack - 0)
    out __SP_H__,r29
    out __SP_L__,r28
/* prologue end (size=4) */
    rcall test
.L3:
    rjmp .L3
/* epilogue: frame size=0 */
/* epilogue: noreturn */
/* epilogue end (size=0) */
/* function main size 6 (2) */
    .size    main, .-main
/* File "aa.c": code   12 = 0x000c (   7), prologues   4, epilogues   1 */


5: 谢谢tczgg仔细看了贴的东西,解决了我不少疑惑,可惜我这边的编译还是通不过…………,我再去看看makefile,有问题再来请教

专家
2022-08-20 15:23:59     打赏
3楼

感谢分享


共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]