IF-THEN Statement??

Status
Not open for further replies.

amady

New Member
Hi all my friend..... i have one question, how i want to do IF-THEN statement using assembly language?
 
amady said:
Hi all my friend..... i have one question, how i want to do IF-THEN statement using assembly language?

By a comparison - and perform a branch depending on the result.

You don't mention your processor, but for a PIC you can use SUB or XOR to perform a comparison, and branch based on the status register results.

If you look on the PICList there's a section about comparisons - and some of my PIC tutorials do them as well, tutorial 9.2 is one that does this - comparing an entered code for a digital lock.
 
if bit 0001 in regx is a one then do subroutine1 else test next bit
if bit 0010 in regx is a one then do subroutine2 else test next bit
if bit 0100 in regx is a one then do subroutine3 else test next
if bit 1000 in reg x is a one then do subroutine4 else exit

where x is any register
test if bit is 1

BTFSC Regx 0x0001 ; if bit 0 in regx = 1 do sub1 else test next bit
Sub1
BTFSC Regx 0x0010 ; if bit 1 in regx = 1 do sub2 else test next bit
Sub2
BTFSC Regx 0X0100 ;if bit 2 in regx = 1 do sub3 else test next bit
Sub3
BTFSC Regx 0x1000;if bit 3 in regx = 1 do sub4 else test next bit
Sub4

similarly
you could test if bit is not set..

BTFSS Regx 0x0001 ; if bit 0 in regx = 0 do sub1 else test next bit
Sub1
BTFSS Regx 0x0010 ; if bit 1 in regx = 0 do sub2 else test next bit
Sub2
BTFSS Regx 0X0100 ;if bit 2 in regx = 0 do sub3 else test next bit
Sub3
BTFSS Regx 0x1000;if bit 3 in regx = 0 do sub4 else test next bit
Sub4
 
Thats exactly how I do it. Not sure if its optimal, but it seems to be the most practical.
 
To nigel and wbill

so if i want to do a range like:

20 (00100000) > Temperature> 15 (00010101)

then to compare (checking from ADC (PIC16F819))... and do a action.

Example:

if temp 20 (00100000) then fan on
if temp 15 (00010101) then fan off

:roll:
 
dak246 said:
Thats exactly how I do it. Not sure if its optimal, but it seems to be the most practical.

That's only checking for a particular bit, not an if/then construct at all!.
 

Presumably you haven't bothered checking on the PICList as I suggested?, here's the exact page for you! .
 
i changed it around now it tests different registers..

BTFSC Regw b'10000000' ; if bit 7 in regw = 1 do sub1 else test next register
Sub1
BTFSC Regx b'10000000' ; if bit 7 in regx = 1 do sub2 else test next register
Sub2
BTFSC Regy b'10000000' ; if bit 7 in regy = 1 do sub3 else test next register
Sub3
BTFSC Regz b'10000000' ; if bit 7 in regz = 1 do sub4 else test next register
Sub4

i dont see how this is not an IF THEN construct

IF (bit 7 in regw is True) THEN (do something) ELSE (do something else)
its making a decision! based on conditions..
 
williB said:
IF (bit 7 in regw is True) THEN (do something) ELSE (do something else)
its making a decision! based on conditions..

OK - it's an IF/THEN/ELSE construct - but not one that's much use :lol:

What's wanted is 'IF regw=13 THEN (do something) ELSE (do something else)'. Or if reg W>3 then...

Checking just a single bit isn't much use except for specialised purposes, and it can only check for eight particular values in a register.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…