Skip to content

Instantly share code, notes, and snippets.

@Flameeyes
Created April 9, 2020 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flameeyes/2c2924d43d612fabbade5d20e41c9f36 to your computer and use it in GitHub Desktop.
Save Flameeyes/2c2924d43d612fabbade5d20e41c9f36 to your computer and use it in GitHub Desktop.
SDCC misapplying operator precedence?
;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.9.0 #11195 (Linux)
;--------------------------------------------------------
.module test
.optsdcc -mmcs51 --model-small
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
.globl _isset2
.globl _isset
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
.area RSEG (ABS,DATA)
.org 0x0000
;--------------------------------------------------------
; special function bits
;--------------------------------------------------------
.area RSEG (ABS,DATA)
.org 0x0000
;--------------------------------------------------------
; overlayable register banks
;--------------------------------------------------------
.area REG_BANK_0 (REL,OVR,DATA)
.ds 8
;--------------------------------------------------------
; internal ram data
;--------------------------------------------------------
.area DSEG (DATA)
;--------------------------------------------------------
; overlayable items in internal ram
;--------------------------------------------------------
.area OSEG (OVR,DATA)
.area OSEG (OVR,DATA)
;--------------------------------------------------------
; indirectly addressable internal ram data
;--------------------------------------------------------
.area ISEG (DATA)
;--------------------------------------------------------
; absolute internal ram data
;--------------------------------------------------------
.area IABS (ABS,DATA)
.area IABS (ABS,DATA)
;--------------------------------------------------------
; bit data
;--------------------------------------------------------
.area BSEG (BIT)
;--------------------------------------------------------
; paged external ram data
;--------------------------------------------------------
.area PSEG (PAG,XDATA)
;--------------------------------------------------------
; external ram data
;--------------------------------------------------------
.area XSEG (XDATA)
;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
.area XABS (ABS,XDATA)
;--------------------------------------------------------
; external initialized ram data
;--------------------------------------------------------
.area XISEG (XDATA)
.area HOME (CODE)
.area GSINIT0 (CODE)
.area GSINIT1 (CODE)
.area GSINIT2 (CODE)
.area GSINIT3 (CODE)
.area GSINIT4 (CODE)
.area GSINIT5 (CODE)
.area GSINIT (CODE)
.area GSFINAL (CODE)
.area CSEG (CODE)
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
.area HOME (CODE)
.area GSINIT (CODE)
.area GSFINAL (CODE)
.area GSINIT (CODE)
;--------------------------------------------------------
; Home
;--------------------------------------------------------
.area HOME (CODE)
.area HOME (CODE)
;--------------------------------------------------------
; code
;--------------------------------------------------------
.area CSEG (CODE)
;------------------------------------------------------------
;Allocation info for local variables in function 'isset'
;------------------------------------------------------------
;input Allocated to registers
;------------------------------------------------------------
; test.c:1: int isset(int input) {
; -----------------------------------------
; function isset
; -----------------------------------------
_isset:
ar7 = 0x07
ar6 = 0x06
ar5 = 0x05
ar4 = 0x04
ar3 = 0x03
ar2 = 0x02
ar1 = 0x01
ar0 = 0x00
; test.c:2: return input & 0xC0 == 0x80;
mov dptr,#0x0000
; test.c:3: }
ret
;------------------------------------------------------------
;Allocation info for local variables in function 'isset2'
;------------------------------------------------------------
;input Allocated to registers r6 r7
;------------------------------------------------------------
; test.c:5: int isset2(int input) {
; -----------------------------------------
; function isset2
; -----------------------------------------
_isset2:
mov r6,dpl
; test.c:6: return (input & 0xC0) == 0x80;
anl ar6,#0xc0
mov r7,#0x00
clr a
cjne r6,#0x80,00103$
cjne r7,#0x00,00103$
inc a
00103$:
mov r6,a
mov r7,#0x00
mov dpl,r6
mov dph,r7
; test.c:7: }
ret
.area CSEG (CODE)
.area CONST (CODE)
.area XINIT (CODE)
.area CABS (ABS,CODE)
int isset(int input) {
return input & 0xC0 == 0x80;
}
int isset2(int input) {
return (input & 0xC0) == 0x80;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment