Skip to content

Instantly share code, notes, and snippets.

@MrTrick
Created July 19, 2011 03:48
Show Gist options
  • Save MrTrick/1091264 to your computer and use it in GitHub Desktop.
Save MrTrick/1091264 to your computer and use it in GitHub Desktop.
AVRGCC Generated ASM code
if (PORTB&(1<<USER_SOL_PIN)) {
48e: c0 9b sbis 0x18, 0 ; 24
490: 02 c0 rjmp .+4 ; 0x496 <main+0x12>
PORTD|=(1<<UV_LAMP_PIN);
492: 97 9a sbi 0x12, 7 ; 18
PORTB&=~(1<<BW_PUMP_PIN);
494: c6 98 cbi 0x18, 6 ; 24
496: ff cf rjmp .-2 ; 0x496 <main+0x12>
Same code generated with macros:
if (read_USER_SOL()) {
484: c0 9b sbis 0x18, 0 ; 24
486: 03 c0 rjmp .+6 ; 0x48e <main+0xa>
write_UV_LAMP(1);
488: 97 9a sbi 0x12, 7 ; 18
write_BW_PUMP(0);
48a: 96 98 cbi 0x12, 6 ; 18
48c: 82 b3 in r24, 0x12 ; 18
}
Macros:
#define _readPIN(port, pin) ( port & _BV(pin) )
#define _writePIN(port, pin, state) ( ( state && (port |= _BV(pin)) ) || (port &= ~_BV(pin)) )
#define read_USER_SOL() _readPIN(PORTB, USER_SOL_PIN)
#define write_UV_LAMP(state) _writePIN(PORTD, UV_LAMP_PIN, state)
#define read_BW_PUMP() _readPIN(PORTD, BW_PUMP_PIN)
if (PORTB&(1<<USER_SOL_PIN)) {
578: 88 e3 ldi r24, 0x38 ; 56
57a: 90 e0 ldi r25, 0x00 ; 0
57c: fc 01 movw r30, r24
57e: 80 81 ld r24, Z
580: 88 2f mov r24, r24
582: 90 e0 ldi r25, 0x00 ; 0
584: 81 70 andi r24, 0x01 ; 1
586: 90 70 andi r25, 0x00 ; 0
588: 88 23 and r24, r24
58a: 91 f0 breq .+36 ; 0x5b0 <main+0x7c>
PORTD|=(1<<UV_LAMP_PIN);
58c: 82 e3 ldi r24, 0x32 ; 50
58e: 90 e0 ldi r25, 0x00 ; 0
590: 22 e3 ldi r18, 0x32 ; 50
592: 30 e0 ldi r19, 0x00 ; 0
594: f9 01 movw r30, r18
596: 20 81 ld r18, Z
598: 20 68 ori r18, 0x80 ; 128
59a: fc 01 movw r30, r24
59c: 20 83 st Z, r18
PORTB&=~(1<<BW_PUMP_PIN);
59e: 88 e3 ldi r24, 0x38 ; 56
5a0: 90 e0 ldi r25, 0x00 ; 0
5a2: 28 e3 ldi r18, 0x38 ; 56
5a4: 30 e0 ldi r19, 0x00 ; 0
5a6: f9 01 movw r30, r18
5a8: 20 81 ld r18, Z
5aa: 2f 7b andi r18, 0xBF ; 191
5ac: fc 01 movw r30, r24
5ae: 20 83 st Z, r18
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment