cancel
Showing results for 
Search instead for 
Did you mean: 

how do you detect zero with a DEC

brian4
Associate II
Posted on March 24, 2003 at 12:25

how do you detect zero with a DEC

9 REPLIES 9
brian4
Associate II
Posted on March 21, 2003 at 08:30

In ST7 code I am DEC a var in RAM.

In ST6 code you could DEC and then JRNZ as the zero flag is set when zero value is reached.

It seems in ST7 the conditional flags are not affected with a RAM variable, is there an easy way to DEC or INC a value and the jump / branch when zero reached.

coor
Associate II
Posted on March 21, 2003 at 09:41

try to OR your val and then check Zero flag

simonharrison9
Associate II
Posted on March 21, 2003 at 12:43

Hi,

I've just tried some code, the Z flag was set when a RAM variable reached zero using DEC

If you do LD A, var

If var is zero the zero flag will be set

Also, if you TNZ var

the z is set if the value of var is zero

Hope this helps

regards,

Simon

[ This message was edited by: sjh on 12-11-2003 16:21 ]
shreya
Associate II
Posted on March 24, 2003 at 00:57

Hello,

The conditional flags are affected by operations on RAM variables too. The instructions for jumping on status of zero flag are JREQ and JRNE, though there is a restriction that the jump is within a range of -127 to +128 bytes around the instruction.

brian4
Associate II
Posted on March 24, 2003 at 05:02

Below is from Page 47 of the ST7 instuction set.

The destination byte is read, then decremented by one, and the result is written at the destination byte. The destination is either a memory byte or a register. This instruction is compact, and does not affect any register when used with RAM variables.

Now I Interpret this as in you DEC A, X & Y then the Z is affected but if you use your own variable then it is not.

I understand that you can load the variable and check it but in the ST6 code you could just to the following:-

DEC secs

JRNZ loop

[ This message was edited by: BrianM on 24-03-2003 09:35 ]
shreya
Associate II
Posted on March 24, 2003 at 06:30

Well,

In ST7 we can say

dec secs

jrne loop

It is better to refer to the STVD7 ''Help on Instruaction'' online help.
simonharrison9
Associate II
Posted on March 24, 2003 at 07:37

Quote:

On 2003-03-24 09:32, BrianM wrote:

Below is from Page 47 of the ST7 instuction set.

This instruction is compact, and does not affect any register when used with RAM variables.

Now I Interpret this as in you DEC A, X & Y then the Z is affected but if you use your own variable then it is not.

This means that A,X and Y are not changed or used in the process.

The status flags are affected.

Simon

stephanie
Associate II
Posted on March 24, 2003 at 09:55

To give a conclusion. Yes, DEC and INC instructions affect N and Z flags (refer to the ST7 instruction set available in this site) whatever the variable is (a register: A, X or Y or a RAM0 variable, which means a variable with a short address (a byte as address)).

So, JRNE or JREQ can be used to branch depending on the Z flag value.

So the code can be:

BYTES

segment 'ram0'

.var DS.B 1

WORDS

segment 'rom'

.main

ld A,#4

ld var,A

again

dec var

jrne again

.....

you'll exit from the dec loop when var=0!

Hope it will help!

A simple way to check this kind of things is to use the simulator STVD7 (given for free on this site) and the ST7 assembly tool chain!

[ This message was edited by: stef on 24-03-2003 14:26 ]

[ This message was edited by: stef on 24-03-2003 14:27 ]
brian4
Associate II
Posted on March 24, 2003 at 12:25

Thank you all for your help