1

Currently I'm using a chip from school which has a limited number of instructions. What I want to achieve is first toggling a single bit with mask and then set some bits to zero. Only 3 instructions available: AND, OR, XOR. (no SHIFT NOT instruction)

for example

0001 1001   // toggle bit 5
0000 1001   
0001 1001   // set bit 1 to 0
0001 1000

I'm trying to generate PWM with H-bridge.

Edit:

Fixed:

; toggle bits
LOAD    R0 [GB+OUTPUT_BUF]
XOR     R0 CONV_FORW_MASK
XOR     R0 FLIP_FORW_MASK
XOR     R0 PUSH_FORW_MASK
XOR     R0 PUSH_BACK_MASK

; set mask bit to zero  
LOAD    R1 PUSH_FORW_MASK
XOR     R1 -1
AND     R0 [R1]
Community
  • 1
  • 1
Yuanlong Li
  • 227
  • 3
  • 9

2 Answers2

1

actually, one instruction, NAND (which is AND with result inverted) would be sufficient, as you can build an XOR (hint, hint) from 4 of those. I'd suggest to start exercising by trying to build an XOR from NANDs only. Then the rest may just fall into place by itself.

Deleted User
  • 2,551
  • 1
  • 11
  • 18
  • with only a NAND or a NOR instruction you can do any logic functions http://en.wikipedia.org/wiki/NAND_logic http://en.wikipedia.org/wiki/NOR_logic – phuclv Jun 11 '14 at 02:08
1

In C it will be :

unsigned char byte = 0x19;

unsigned char bit_set = (0x01 & byte) ^ byte;

unsigned char bit_toggle = ((byte ^ 0x10) & 0x10);

byte = ( byte & 0xEF ) | bit_toggle ;

Now translate to assembly.

lsalamon
  • 7,998
  • 6
  • 50
  • 63