You are here

Handling Two byte variables in assembly | Cypress Semiconductor

Support & Community

Handling Two byte variables in assembly

Last Updated: March 27, 2011

How to perform arithmetic operations on a two bytes variable in assembly language?


Since PSoC is an 8 bit MCU, there are no instructions to process 16 bit data directly. Please use carry to perform 2 byte arithmetic. Following is an example for a loop of 500 counts.

Variable Declaration:

area bss(ram)
loopCount: BLK 2


mov [loopCount+1],f4h
mov [loopCount],1 ;load 500 to loopCount

;Write your code that has to be performed within the loop

sub [loopCount+1],1  // Subtract 1 from LSB
sbb [loopCount],0     // Subtract with borrow from MSB
jnc loop

Similarly for addition, use the "add" and "adc" instructions.

Knowledge Base Tags: 

Provide feedback on this article

Browse KB By Product

Browse KB by Type