Avr8bit-emulator
An emulator for the Atmel AVR 8-bit microcontroller
Loading...
Searching...
No Matches
branch.h File Reference

Branching and jumps instructions. More...

#include <stdint.h>
#include <stdbool.h>
#include "core.h"
#include "sram.h"
#include "data_space.h"
#include "sreg_utils.h"
#include "emulator.h"
Include dependency graph for branch.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void rjmp (uint8_t k, struct CORE *core)
 Perform a relative jump.
 
void ijmp (struct CORE *core)
 Perform an indirect jump.
 
void jmp (uint32_t k, struct CORE *core)
 Perform an absolute jump.
 
void rcall (uint8_t k, struct CORE *core, struct SRAM *sram)
 Perform a relative call to a subroutine.
 
void icall (struct CORE *core, struct SRAM *sram)
 Perform an indirect call to a subroutine.
 
void eicall (struct CORE *core, struct SRAM *sram)
 Perform an extended indirect call to a subroutine.
 
void ret (struct CORE *core, struct SRAM *sram)
 Return from a subroutine.
 
void reti (struct CORE *core, struct SRAM *sram)
 Return from an interrupt.
 
void cpse (uint8_t d, uint8_t r, struct CORE *core)
 Compare and skip if equal.
 
void cp (uint8_t d, uint8_t r, struct CORE *core)
 Compare two registers.
 
void cpc (uint8_t d, uint8_t r, struct CORE *core)
 Compare two registers with carry.
 
void cpi (uint8_t d, uint8_t K, struct CORE *core)
 Compare register with an immediate value.
 
void sbrc (uint8_t r, uint8_t b, struct CORE *core)
 Skip if bit in register is cleared.
 
void sbrs (uint8_t r, uint8_t b, struct CORE *core)
 Skip if bit in register is set.
 
void sbic (uint8_t A, uint8_t b, struct CORE *core, union DATA_SPACE *data_space)
 Skip if bit in I/O register is cleared.
 
void sbis (uint8_t A, uint8_t b, struct CORE *core, union DATA_SPACE *data_space)
 Skip if bit in I/O register is set.
 
void brbs (uint8_t s, uint8_t k, struct CORE *core)
 Branch if status flag is set.
 
void brbc (uint8_t s, uint8_t k, struct CORE *core)
 Branch if status flag is cleared.
 
void breq (uint8_t k, struct CORE *core)
 Branch if equal.
 
void brne (uint8_t k, struct CORE *core)
 Branch if not equal.
 
void brcs (uint8_t k, struct CORE *core)
 Branch if carry set.
 
void brcc (uint8_t k, struct CORE *core)
 Branch if carry cleared.
 
void brsh (uint8_t k, struct CORE *core)
 Branch if same or higher.
 
void brlo (uint8_t k, struct CORE *core)
 Branch if lower.
 
void brmi (uint8_t k, struct CORE *core)
 Branch if minus.
 
void brpl (uint8_t k, struct CORE *core)
 Branch if plus.
 
void brge (uint8_t k, struct CORE *core)
 Branch if greater or equal.
 
void brlt (uint8_t k, struct CORE *core)
 Branch if less than.
 
void brhs (uint8_t k, struct CORE *core)
 Branch if half carry set.
 
void brhc (uint8_t k, struct CORE *core)
 Branch if half carry cleared.
 
void brts (uint8_t k, struct CORE *core)
 Branch if T flag set.
 
void brtc (uint8_t k, struct CORE *core)
 Branch if T flag cleared.
 
void brvs (uint8_t k, struct CORE *core)
 Branch if overflow set.
 
void brvc (uint8_t k, struct CORE *core)
 Branch if overflow cleared.
 
void brie (uint8_t k, struct CORE *core)
 Branch if interrupts enabled.
 
void brid (uint8_t k, struct CORE *core)
 Branch if interrupts disabled.
 

Detailed Description

Branching and jumps instructions.

Contains all atomic branching and jumps instructions

Author
Antonin Pivard
Date
2024
Warning
Not tested

Definition in file branch.h.

Function Documentation

◆ brbc()

void brbc ( uint8_t  s,
uint8_t  k,
struct CORE core 
)

Branch if status flag is cleared.

Parameters
sStatus flag.
kRelative address.
corePointer to the CORE structure.

Definition at line 247 of file branch.c.

247 {
248 // Branch if bit in SREG cleared
249 // If S(s) = 0, PC <- PC + k + 1
250 // 1 cycle
251
252 // Execute instruction
253 if ((core->sreg.sreg & (1 << s)) == 0) {
254 core->PC = core->PC + k + 1;
255 }
256 else {
257 core->PC = core->PC + 1;
258 }
259
260 // Update SREG
261 // NONE
262}
uint32_t PC
Definition core.h:69
union SREG sreg
Definition core.h:71
uint8_t sreg
Definition core.h:11

References CORE::PC, SREG::sreg, and CORE::sreg.

◆ brbs()

void brbs ( uint8_t  s,
uint8_t  k,
struct CORE core 
)

Branch if status flag is set.

Parameters
sStatus flag.
kRelative address.
corePointer to the CORE structure.

Definition at line 230 of file branch.c.

230 {
231 // Branch if bit in SREG set
232 // If S(s) = 1, PC <- PC + k + 1
233 // 1 cycle
234
235 // Execute instruction
236 if ((core->sreg.sreg & (1 << s)) == 1) {
237 core->PC = core->PC + k + 1;
238 }
239 else {
240 core->PC = core->PC + 1;
241 }
242
243 // Update SREG
244 // NONE
245}

References CORE::PC, SREG::sreg, and CORE::sreg.

◆ brcc()

void brcc ( uint8_t  k,
struct CORE core 
)

Branch if carry cleared.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 315 of file branch.c.

315 {
316 // Branch if carry cleared
317 // If C = 0, PC <- PC + k + 1
318 // 1 cycle
319
320 // Execute instruction
321 if (core->sreg.C == 0) {
322 core->PC = core->PC + k + 1;
323 }
324 else {
325 core->PC = core->PC + 1;
326 }
327
328 // Update SREG
329 // NONE
330}
bool C
Definition core.h:13

References SREG::C, CORE::PC, and CORE::sreg.

◆ brcs()

void brcs ( uint8_t  k,
struct CORE core 
)

Branch if carry set.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 298 of file branch.c.

298 {
299 // Branch if carry set
300 // If C = 1, PC <- PC + k + 1
301 // 1 cycle
302
303 // Execute instruction
304 if (core->sreg.C == 1) {
305 core->PC = core->PC + k + 1;
306 }
307 else {
308 core->PC = core->PC + 1;
309 }
310
311 // Update SREG
312 // NONE
313}

References SREG::C, CORE::PC, and CORE::sreg.

◆ breq()

void breq ( uint8_t  k,
struct CORE core 
)

Branch if equal.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 264 of file branch.c.

264 {
265 // Branch if equal
266 // If Z = 1, PC <- PC + k + 1
267 // 1 cycle
268
269 // Execute instruction
270 if (core->sreg.Z == 1) {
271 core->PC = core->PC + k + 1;
272 }
273 else {
274 core->PC = core->PC + 1;
275 }
276
277 // Update SREG
278 // NONE
279}
bool Z
Definition core.h:14

References CORE::PC, CORE::sreg, and SREG::Z.

◆ brge()

void brge ( uint8_t  k,
struct CORE core 
)

Branch if greater or equal.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 400 of file branch.c.

400 {
401 // Branch if greater or equal
402 // If N = V, PC <- PC + k + 1
403 // 1 cycle
404
405 // Execute instruction
406 if (core->sreg.N == core->sreg.V) {
407 core->PC = core->PC + k + 1;
408 }
409 else {
410 core->PC = core->PC + 1;
411 }
412
413 // Update SREG
414 // NONE
415}
bool N
Definition core.h:15
bool V
Definition core.h:16

References SREG::N, CORE::PC, CORE::sreg, and SREG::V.

◆ brhc()

void brhc ( uint8_t  k,
struct CORE core 
)

Branch if half carry cleared.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 451 of file branch.c.

451 {
452 // Branch if half carry cleared
453 // If H = 0, PC <- PC + k + 1
454 // 1 cycle
455
456 // Execute instruction
457 if (core->sreg.H == 0) {
458 core->PC = core->PC + k + 1;
459 }
460 else {
461 core->PC = core->PC + 1;
462 }
463
464 // Update SREG
465 // NONE
466}
bool H
Definition core.h:18

References SREG::H, CORE::PC, and CORE::sreg.

◆ brhs()

void brhs ( uint8_t  k,
struct CORE core 
)

Branch if half carry set.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 434 of file branch.c.

434 {
435 // Branch if half carry set
436 // If H = 1, PC <- PC + k + 1
437 // 1 cycle
438
439 // Execute instruction
440 if (core->sreg.H == 1) {
441 core->PC = core->PC + k + 1;
442 }
443 else {
444 core->PC = core->PC + 1;
445 }
446
447 // Update SREG
448 // NONE
449}

References SREG::H, CORE::PC, and CORE::sreg.

◆ brid()

void brid ( uint8_t  k,
struct CORE core 
)

Branch if interrupts disabled.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 553 of file branch.c.

553 {
554 // Branch if global interrupt disabled
555 // If I = 0, PC <- PC + k + 1
556 // 1 cycle
557
558 // Execute instruction
559 if (core->sreg.I == 0) {
560 core->PC = core->PC + k + 1;
561 }
562 else {
563 core->PC = core->PC + 1;
564 }
565
566 // Update SREG
567 // NONE
568}
bool I
Definition core.h:20

References SREG::I, CORE::PC, and CORE::sreg.

◆ brie()

void brie ( uint8_t  k,
struct CORE core 
)

Branch if interrupts enabled.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 536 of file branch.c.

536 {
537 // Branch if global interrupt enabled
538 // If I = 1, PC <- PC + k + 1
539 // 1 cycle
540
541 // Execute instruction
542 if (core->sreg.I == 1) {
543 core->PC = core->PC + k + 1;
544 }
545 else {
546 core->PC = core->PC + 1;
547 }
548
549 // Update SREG
550 // NONE
551}

References SREG::I, CORE::PC, and CORE::sreg.

◆ brlo()

void brlo ( uint8_t  k,
struct CORE core 
)

Branch if lower.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 349 of file branch.c.

349 {
350 // Branch if lower
351 // If C = 0, PC <- PC + k + 1
352 // 1 cycle
353
354 // Execute instruction
355 if (core->sreg.C == 0) {
356 core->PC = core->PC + k + 1;
357 }
358 else {
359 core->PC = core->PC + 1;
360 }
361
362 // Update SREG
363 // NONE
364}

References SREG::C, CORE::PC, and CORE::sreg.

◆ brlt()

void brlt ( uint8_t  k,
struct CORE core 
)

Branch if less than.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 417 of file branch.c.

417 {
418 // Branch if less than
419 // If N != V, PC <- PC + k + 1
420 // 1 cycle
421
422 // Execute instruction
423 if (core->sreg.N != core->sreg.V) {
424 core->PC = core->PC + k + 1;
425 }
426 else {
427 core->PC = core->PC + 1;
428 }
429
430 // Update SREG
431 // NONE
432}

References SREG::N, CORE::PC, CORE::sreg, and SREG::V.

◆ brmi()

void brmi ( uint8_t  k,
struct CORE core 
)

Branch if minus.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 366 of file branch.c.

366 {
367 // Branch if minus
368 // If N = 1, PC <- PC + k + 1
369 // 1 cycle
370
371 // Execute instruction
372 if (core->sreg.N == 1) {
373 core->PC = core->PC + k + 1;
374 }
375 else {
376 core->PC = core->PC + 1;
377 }
378
379 // Update SREG
380 // NONE
381}

References SREG::N, CORE::PC, and CORE::sreg.

◆ brne()

void brne ( uint8_t  k,
struct CORE core 
)

Branch if not equal.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 281 of file branch.c.

281 {
282 // Branch if not equal
283 // If Z = 0, PC <- PC + k + 1
284 // 1 cycle
285
286 // Execute instruction
287 if (core->sreg.Z == 0) {
288 core->PC = core->PC + k + 1;
289 }
290 else {
291 core->PC = core->PC + 1;
292 }
293
294 // Update SREG
295 // NONE
296}

References CORE::PC, CORE::sreg, and SREG::Z.

◆ brpl()

void brpl ( uint8_t  k,
struct CORE core 
)

Branch if plus.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 383 of file branch.c.

383 {
384 // Branch if plus
385 // If N = 0, PC <- PC + k + 1
386 // 1 cycle
387
388 // Execute instruction
389 if (core->sreg.N == 0) {
390 core->PC = core->PC + k + 1;
391 }
392 else {
393 core->PC = core->PC + 1;
394 }
395
396 // Update SREG
397 // NONE
398}

References SREG::N, CORE::PC, and CORE::sreg.

◆ brsh()

void brsh ( uint8_t  k,
struct CORE core 
)

Branch if same or higher.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 332 of file branch.c.

332 {
333 // Branch if same or higher
334 // If C = 1, PC <- PC + k + 1
335 // 1 cycle
336
337 // Execute instruction
338 if (core->sreg.C == 1) {
339 core->PC = core->PC + k + 1;
340 }
341 else {
342 core->PC = core->PC + 1;
343 }
344
345 // Update SREG
346 // NONE
347}

References SREG::C, CORE::PC, and CORE::sreg.

◆ brtc()

void brtc ( uint8_t  k,
struct CORE core 
)

Branch if T flag cleared.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 485 of file branch.c.

485 {
486 // Branch if T flag cleared
487 // If T = 0, PC <- PC + k + 1
488 // 1 cycle
489
490 // Execute instruction
491 if (core->sreg.T == 0) {
492 core->PC = core->PC + k + 1;
493 }
494 else {
495 core->PC = core->PC + 1;
496 }
497
498 // Update SREG
499 // NONE
500}
bool T
Definition core.h:19

References CORE::PC, CORE::sreg, and SREG::T.

◆ brts()

void brts ( uint8_t  k,
struct CORE core 
)

Branch if T flag set.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 468 of file branch.c.

468 {
469 // Branch if T flag set
470 // If T = 1, PC <- PC + k + 1
471 // 1 cycle
472
473 // Execute instruction
474 if (core->sreg.T == 1) {
475 core->PC = core->PC + k + 1;
476 }
477 else {
478 core->PC = core->PC + 1;
479 }
480
481 // Update SREG
482 // NONE
483}

References CORE::PC, CORE::sreg, and SREG::T.

◆ brvc()

void brvc ( uint8_t  k,
struct CORE core 
)

Branch if overflow cleared.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 519 of file branch.c.

519 {
520 // Branch if overflow cleared
521 // If V = 0, PC <- PC + k + 1
522 // 1 cycle
523
524 // Execute instruction
525 if (core->sreg.V == 0) {
526 core->PC = core->PC + k + 1;
527 }
528 else {
529 core->PC = core->PC + 1;
530 }
531
532 // Update SREG
533 // NONE
534}

References CORE::PC, CORE::sreg, and SREG::V.

◆ brvs()

void brvs ( uint8_t  k,
struct CORE core 
)

Branch if overflow set.

Parameters
kThe offset for the branch.
corePointer to the core structure.

Definition at line 502 of file branch.c.

502 {
503 // Branch if overflow set
504 // If V = 1, PC <- PC + k + 1
505 // 1 cycle
506
507 // Execute instruction
508 if (core->sreg.V == 1) {
509 core->PC = core->PC + k + 1;
510 }
511 else {
512 core->PC = core->PC + 1;
513 }
514
515 // Update SREG
516 // NONE
517}

References CORE::PC, CORE::sreg, and SREG::V.

◆ cp()

void cp ( uint8_t  d,
uint8_t  r,
struct CORE core 
)

Compare two registers.

Parameters
dDestination register.
rSource register.
corePointer to the CORE structure.

Definition at line 120 of file branch.c.

120 {
121 // Compare
122 // Rd - Rr
123 // 1 cycle
124
125 // Execute instruction
126 uint8_t result = core->gp.R[d] - core->gp.R[r];
127
128 // Update SREG
129 update_sreg_arithm(core, core->gp.R[d], core->gp.R[r], result);
130}
void update_sreg_arithm(struct CORE *core, uint8_t Rd, uint8_t Rr, uint8_t result)
Updates the Status Register (SREG) for arithmetic operations.
Definition sreg_utils.c:51
union GP gp
Definition core.h:68
uint8_t R[32]
Definition core.h:29

References CORE::gp, GP::R, and update_sreg_arithm().

◆ cpc()

void cpc ( uint8_t  d,
uint8_t  r,
struct CORE core 
)

Compare two registers with carry.

Parameters
dDestination register.
rSource register.
corePointer to the CORE structure.

Definition at line 132 of file branch.c.

132 {
133 // Compare with carry
134 // Rd - Rr - C
135 // 1 cycle
136
137 // Execute instruction
138 uint8_t result = core->gp.R[d] - core->gp.R[r] - core->sreg.C;
139
140 // Update SREG
141 update_sreg_arithm(core, core->gp.R[d], core->gp.R[r], result);
142}

References SREG::C, CORE::gp, GP::R, CORE::sreg, and update_sreg_arithm().

◆ cpi()

void cpi ( uint8_t  d,
uint8_t  K,
struct CORE core 
)

Compare register with an immediate value.

Parameters
dDestination register.
KImmediate value.
corePointer to the CORE structure.

Definition at line 144 of file branch.c.

144 {
145 // Compare with immediate
146 // Rd - K
147 // 1 cycle
148
149 // Execute instruction
150 uint8_t result = core->gp.R[d] - K;
151
152 // Update SREG
153 update_sreg_arithm(core, core->gp.R[d], K, result);
154}

References CORE::gp, GP::R, and update_sreg_arithm().

◆ cpse()

void cpse ( uint8_t  d,
uint8_t  r,
struct CORE core 
)

Compare and skip if equal.

Parameters
dThe destination register.
rThe source register.
corePointer to the CORE structure.

Definition at line 102 of file branch.c.

102 {
103 // Compare, skip if equal
104 // If Rd = Rr, PC <- PC + 2
105 // 1 cycle
106
107 // Execute instruction
108 if (core->gp.R[d] == core->gp.R[r]) {
109 core->PC = core->PC + 2;
110 // LACKS IMPLEMENTATION + 3 if instruction skipped is 2word long
111 }
112 else {
113 core->PC = core->PC + 1;
114 }
115
116 // Update SREG
117 // NONE
118}

References CORE::gp, CORE::PC, and GP::R.

◆ eicall()

void eicall ( struct CORE core,
struct SRAM sram 
)

Perform an extended indirect call to a subroutine.

Parameters
corePointer to the CORE structure.
sramPointer to the SRAM structure.

◆ icall()

void icall ( struct CORE core,
struct SRAM sram 
)

Perform an indirect call to a subroutine.

Parameters
corePointer to the CORE structure.
sramPointer to the SRAM structure.

Definition at line 54 of file branch.c.

54 {
55 // Indirect call to address contained in Z
56 // PC <- Z
57 // Push return address to stack
58 // 3 cycles
59
60 // Execute instruction
61 sram->mem[core->SP] = core->PC + 1;
62 core->SP = core->SP - 2;
63 core->PC = core->gp.Z;
64
65 // Update SREG
66 // NONE
67}
uint16_t SP
Definition core.h:70
uint8_t mem[SRAM_SIZE]
Definition sram.h:8
uint16_t Z
Definition core.h:59

References CORE::gp, SRAM::mem, CORE::PC, CORE::SP, and GP::Z.

◆ ijmp()

void ijmp ( struct CORE core)

Perform an indirect jump.

Parameters
corePointer to the CORE structure.

Definition at line 15 of file branch.c.

15 {
16 // Indirect jump to address contained in Z
17 // PC <- Z
18 // 2 cycles
19
20 // Execute instruction
21 core->PC = core->gp.R[30] << 8 | core->gp.R[31];
22
23 // Update SREG
24 // NONE
25}

References CORE::gp, CORE::PC, and GP::R.

◆ jmp()

void jmp ( uint32_t  k,
struct CORE core 
)

Perform an absolute jump.

Parameters
kThe address to jump to.
corePointer to the CORE structure.

Definition at line 27 of file branch.c.

27 {
28 // Absolute jump
29 // PC <- k
30 // 3 cycles
31
32 // Execute instruction
33 core->PC = k;
34
35 // Update SREG
36 // NONE
37}

References CORE::PC.

◆ rcall()

void rcall ( uint8_t  k,
struct CORE core,
struct SRAM sram 
)

Perform a relative call to a subroutine.

Parameters
kThe offset for the call.
corePointer to the CORE structure.
sramPointer to the SRAM structure.

Definition at line 39 of file branch.c.

39 {
40 // Relative call
41 // PC <- PC + k + 1
42 // Push return address to stack
43 // 3 cycles
44
45 // Execute instruction
46 sram->mem[core->SP] = core->PC + 1;
47 core->SP = core->SP - 2;
48 core->PC = core->PC + k + 1;
49
50 // Update SREG
51 // NONE
52}

References SRAM::mem, CORE::PC, and CORE::SP.

◆ ret()

void ret ( struct CORE core,
struct SRAM sram 
)

Return from a subroutine.

Parameters
corePointer to the CORE structure.
sramPointer to the SRAM structure.

Definition at line 73 of file branch.c.

73 {
74 // Return from subroutine
75 // Pop return address from stack
76 // PC <- (SP + 1)
77 // 4 cycles
78
79 // Execute instruction
80 core->SP = core->SP + 1;
81 core->PC = sram->mem[core->SP] << 8 | sram->mem[core->SP + 1];
82
83 // Update SREG
84 // NONE
85}

References SRAM::mem, CORE::PC, and CORE::SP.

◆ reti()

void reti ( struct CORE core,
struct SRAM sram 
)

Return from an interrupt.

Parameters
corePointer to the CORE structure.
sramPointer to the SRAM structure.

Definition at line 87 of file branch.c.

87 {
88 // Return from interrupt
89 // Pop return address from stack
90 // PC <- (SP + 1)
91 // Enable global interrupts
92 // 4 cycles
93
94 // Execute instruction
95 core->SP = core->SP + 1;
96 core->PC = sram->mem[core->SP] << 8 | sram->mem[core->SP + 1];
97
98 // Update SREG
99 update_sreg_I(&core->sreg, true);
100}
void update_sreg_I(struct CORE *core, bool state)
Update the Interrupt flag (I) in the status register.
Definition sreg_utils.c:103

References SRAM::mem, CORE::PC, CORE::SP, CORE::sreg, and update_sreg_I().

◆ rjmp()

void rjmp ( uint8_t  k,
struct CORE core 
)

Perform a relative jump.

Parameters
kThe offset for the jump.
corePointer to the CORE structure.

Definition at line 3 of file branch.c.

3 {
4 // Relative jump
5 // PC <- PC + k + 1
6 // 2 cycles
7
8 // Execute instruction
9 core->PC = core->PC + k + 1;
10
11 // Update SREG
12 // NONE
13}

References CORE::PC.

◆ sbic()

void sbic ( uint8_t  A,
uint8_t  b,
struct CORE core,
union DATA_SPACE data_space 
)

Skip if bit in I/O register is cleared.

Parameters
AI/O register address.
bBit position.
corePointer to the CORE structure.
data_spacePointer to the DATA_SPACE union.

Definition at line 192 of file branch.c.

192 {
193 // Skip if bit in I/O register cleared
194 // Only for 0 <= A <= 31
195 // If I/O(A)(b) = 0, PC <- PC + 2
196 // 1 cycle
197
198 // Execute instruction
199 if ((data_space->io_reg[A] & (1 << b)) == 0) {
200 core->PC = core->PC + 2;
201 // LACKS IMPLEMENTATION + 3 if instruction skipped is 2word long
202 }
203 else {
204 core->PC = core->PC + 1;
205 }
206
207 // Update SREG
208 // NONE
209}
uint8_t io_reg[64]
Definition data_space.h:17

References DATA_SPACE::io_reg, and CORE::PC.

◆ sbis()

void sbis ( uint8_t  A,
uint8_t  b,
struct CORE core,
union DATA_SPACE data_space 
)

Skip if bit in I/O register is set.

Parameters
AI/O register address.
bBit position.
corePointer to the CORE structure.
data_spacePointer to the DATA_SPACE union.

Definition at line 211 of file branch.c.

211 {
212 // Skip if bit in I/O register set
213 // Only for 0 <= A <= 31
214 // If I/O(A)(b) = 1, PC <- PC + 2
215 // 1 cycle
216
217 // Execute instruction
218 if ((data_space->io_reg[A] & (1 << b)) == 1) {
219 core->PC = core->PC + 2;
220 // LACKS IMPLEMENTATION + 3 if instruction skipped is 2word long
221 }
222 else {
223 core->PC = core->PC + 1;
224 }
225
226 // Update SREG
227 // NONE
228}

References DATA_SPACE::io_reg, and CORE::PC.

◆ sbrc()

void sbrc ( uint8_t  r,
uint8_t  b,
struct CORE core 
)

Skip if bit in register is cleared.

Parameters
rRegister.
bBit position.
corePointer to the CORE structure.

Definition at line 156 of file branch.c.

156 {
157 // Skip if bit in register cleared
158 // If Rr(b) = 0, PC <- PC + 2
159 // 1 cycle
160
161 // Execute instruction
162 if ((core->gp.R[r] & (1 << b)) == 0) {
163 core->PC = core->PC + 2;
164 // LACKS IMPLEMENTATION + 3 if instruction skipped is 2word long
165 }
166 else {
167 core->PC = core->PC + 1;
168 }
169
170 // Update SREG
171 // NONE
172}

References CORE::gp, CORE::PC, and GP::R.

◆ sbrs()

void sbrs ( uint8_t  r,
uint8_t  b,
struct CORE core 
)

Skip if bit in register is set.

Parameters
rRegister.
bBit position.
corePointer to the CORE structure.

Definition at line 174 of file branch.c.

174 {
175 // Skip if bit in register set
176 // If Rr(b) = 1, PC <- PC + 2
177 // 1 cycle
178
179 // Execute instruction
180 if ((core->gp.R[r] & (1 << b)) == 1) {
181 core->PC = core->PC + 2;
182 // LACKS IMPLEMENTATION + 3 if instruction skipped is 2word long
183 }
184 else {
185 core->PC = core->PC + 1;
186 }
187
188 // Update SREG
189 // NONE
190}

References CORE::gp, CORE::PC, and GP::R.