-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path39_set_clear_bits.asm
More file actions
23 lines (21 loc) · 979 Bytes
/
39_set_clear_bits.asm
File metadata and controls
23 lines (21 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
; Exercise 39: Set and Clear Bits
; Level: 6 - Bit Manipulation
;
; Goal: Set specific bits to 1 using OR, clear specific bits to 0 using AND
; Start with 0x00, set bits 0 and 4, then clear bit 0
;
; Instructions to use: LOADI, OR, AND, HALT
; Expected result: R0 = 0x10 (only bit 4 set)
;
; Hint: OR with 1-bits sets those bits: value | mask
; Hint: AND with 0-bits clears those bits: value & ~mask
; Hint: To clear bit N: AND with value that has bit N = 0, all others = 1
section .code
loadi r0, 0b00000000 ; Load 0x00 into R0 (start with all bits clear)
loadi r1, 0b00010001 ; Load 0x11 into R1 (mask for bits 0 and 4: 00010001)
or r0, r1 ; OR R0 with R1 (set bits 0 and 4: R0 = 0x11)
; 0b00010001
loadi r1, 0b11111110 ; Load 0xFE into R1 (mask to clear bit 0: 11111110)
and r0, r1 ; AND R0 with R1 (clear bit 0: R0 = 0x10)
; 0b00010000
halt ; Halt (R0 should be 0x10)