まつぞの@しつこくってすみません です
代入文ですらない場合もテストしてみました
結論を先にいうと、H8, AVR とも OK (最適化されない)でした
他のコンパイラではどうなのでしょうか。。。
# すみません、手元にあるクロスコンパイラって GCC だけなんです
-------------------------------------------------------------
// io_read.c
// volatile 指定で最適化がされる場合があるかどうかテストする
#ifdef VOLATILE_DEFINED
volatile int count;
#else
int count;
#endif
int main(){
int a;
count;
count;
count; // ううっ、さすがにこう書くと気持ち悪い(^^;;
return 0;
}
---------------------------------------------------------------
$ h8300-hms-gcc -o H8_volatile_O9.S -S -O9 -DVOLATILE_DEFINED io_read.c
----------------- H8_volatile_09.S ----------------------------
; GCC For the Hitachi H8/300
; By Hitachi America Ltd and Cygnus Support
; -O9
.file "io_read.c"
.comm _count,2
.section .text
.align 1
.global _main
_main:
push r6
mov.w r7,r6
mov.w @_count,r2
mov.w @_count,r2
mov.w @_count,r2
sub.w r0,r0
pop r6
rts
.end
.ident
"GCC: (GNU) 3.0.3"
---------------------------------------------------------------
$ avr-gcc -o AVR_volatile_O9.S -O9 -S -DVOLATILE_DEFINED io_read.c
----------------- AVR_volatile_09.S ----------------------------
.file "io_read.c"
.arch avr2
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
_PC_ = 2
.text
.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) */
lds r24,count
lds r25,(count)+1
lds r24,count
lds r25,(count)+1
lds r24,count
lds r25,(count)+1
ldi r24,lo8(0)
ldi r25,hi8(0)
/* epilogue: frame size=0 */
__stop_progIi__:
rjmp __stop_progIi__
/* epilogue end (size=1) */
/* function main size 19 (14) */
.Lfe1:
.size main,.Lfe1-main
.comm count,2,1
/* File io_read.c: code 19 = 0x0013 ( 14), prologues 4, epilogues 1 */
---------------------------------------------------------------