movlw suspicious asm output
Posted: Wed Sep 25, 2013 11:05 am
I can't recall if I ever mentioned this or not, but I ran across a situation where the compiler produced some questionable ASM...
MPASM truncates the value, so it's not seen as an error. It does issue a warning, but that's masked out since the MPASM command line switches are set to '/w2'. In the past I've seen other cases where MOVLW has values > 255 as an argument.
It's interesting that the same code produces two different outputs.
Code: Select all
program main
public dim errno as shortint
const ERR_CODE as shortint = -3
public sub dummy()
// this produces 'movlw 65533' ???
errno = ERR_CODE
end sub
// this produces 'movlw 253'
errno = ERR_CODE
dummy()
{
; DUMMY
PROC_L00000000
?I000000_F000_000008_P000001 ; L#MK ERRNO = ERR_CODE
MOVLW 65533
MOVWF M0_S08,0
?I000001_F000_000009_P000001 ; L#MK END SUB
RETURN 0
MAIN
?I000002_F000_000011_M000000 ; L#MK ERRNO = ERR_CODE
MOVLW 253
MOVWF M0_S08,0
?I000003_F000_000012_M000000 ; L#MK DUMMY()
RCALL PROC_L00000000
?I000004_END; L#MK
}
It's interesting that the same code produces two different outputs.