PDA

View Full Version : True/false



Mike_Z
March 3rd, 2017, 07:22 AM
I want to make a variable either TRUE or FALSE and to be able to change that variable during the program. I started out with;



TRUE: EQU 0FFH
FALSE: EQU NOT TRUE

SHIFT: EQU FALSE

PROG: (Do Stuff)
Then how to I change SHIFT to TRUE?
I tried;

SHIFT: SET TRUE ;This did not work


So... how should I change SHIFT when I need to? Mike

Mike_Z
March 3rd, 2017, 07:44 AM
I also tried this;



IF SHIFT NOT TRUE
SHIFT: EQU FALSE
ENDIF


This didn't work either. Mike

NF6X
March 3rd, 2017, 07:50 AM
The EQU directive defines constants to be used during assembly. Those constants do not have any space allocated in the target's memory to store their values, and they cannot be changed at run-time. What you need to do is to allocate a byte of memory to hold the value of SHIFT, which you can then reference and change in your program at runtime.

Uh, I'm not too familiar with the assemblers under CP/M yet, but I think it would look something like this:


TRUE: EQU 0FFH
FALSE: EQU NOT TRUE

PROG1: (do stuff)

SHIFT: DB TRUE

PROG2: (do more stuff)

Your code can test and change the value of SHIFT like any other memory byte.

The IF directive also only acts at assembly time. It can be used to tell the assembler which code to assemble; if the IF statement is true, then the following code is assembled, and if it is not true then the following code is ignored. The IF statement does not generate any executable code by itself, and it doesn't act at runtime.

Chuck(G)
March 3rd, 2017, 07:56 AM
This should be self-explanatory:


00FF = TRUE EQU 0FFH
0000 = FALSE EQU NOT TRUE AND 0FFH

SHIFT SET TRUE

0000 FF DB SHIFT

SHIFT SET FALSE

0001 00 DB SHIFT

0002 end

smp
March 3rd, 2017, 07:56 AM
I think your code is dealing with assembler directives. These will only be looked at by the assembler during the assembly process.

You should make a variable that will actually be in your RAM during program operation:

SHIFT DB 0FFH

Then, during program operation, you may change that byte to be whatever you wish:

MVI A,0
STA SHIFT

Give that a try...

smp

Mike_Z
March 3rd, 2017, 08:28 AM
You know, maybe I read that or heard it, but didn't understand the concept until now. The fact that the EQU only defines the constant during assemble, while the DB sets aside a memory location that can be manipulated during run time. I also didn't understand the facts about the IF/ENDIF, but that will be work for another time. Thanks a bunch for the examples, I learn best by example. I'd like to ask why you would use this statement,

FALSE EQU NOT TRUE AND 0FFH

why add the AND 0FFH. I understand you are logically anding the not true with ones.

I also tried the LXI H,SHIFT MVI M,0H

Works great. Thanks for the help Mike.

Mike_Z
March 3rd, 2017, 08:34 AM
I also tried this, but it did not work. It reported a Value error.



LXI H,SHIFT
MVI M,FALSE


Mike

Chuck(G)
March 3rd, 2017, 08:55 AM
You know, maybe I read that or heard it, but didn't understand the concept until now. The fact that the EQU only defines the constant during assemble, while the DB sets aside a memory location that can be manipulated during run time. I also didn't understand the facts about the IF/ENDIF, but that will be work for another time. Thanks a bunch for the examples, I learn best by example. I'd like to ask why you would use this statement,

FALSE EQU NOT TRUE AND 0FFH

why add the AND 0FFH. I understand you are logically anding the not true with ones.

I also tried the LXI H,SHIFT MVI M,0H

Works great. Thanks for the help Mike.

ASM assumes a 16-bit value for all assembly constants (i.e. they're monotyped). If one bits are lost when applying them (truncating to byte), you get an error. Follow along with me here;

TRUE EQU 0FFH
FALSE EQU NOT TRUE

Assigns a value of 0FF00H to "FALSE", which is not what you want.

FALSE EQU NOT TRUE AND 0FFH

gives you a value of 0000H, which is what you want--something that can be safely truncated to a byte value.

You could just as easily code:

FALSE EQU 0
TRUE EQU NOT FALSE

and then apply it as a byte quantity:

MVI M,TRUE AND 0FFH

--but that seems a bit more awkward to me.

KC9UDX
March 3rd, 2017, 09:51 AM
It's been a long time since I did anything Datapoint 2200 related, so perhaps I'm thinking too 65xx, but isn't it usually easier to make TRUE equal to 0 and FALSE equal to a single high bit (any position, but preferably bit 0 for ease of remembrance, or 6 or 7 for smaller code)?

Chuck(G)
March 3rd, 2017, 09:55 AM
It doesn't really matter for the 808x. It all depends on your use--the ISA isn't biased either way. e.g.,

ORA A
JZ xxx

KC9UDX
March 3rd, 2017, 10:04 AM
Nevermind, I'm thinking too much into it.

In 6502, the ORA A is totally unnecessary, for reasons which I realise don't apply to 8080.

Mike_Z
March 3rd, 2017, 10:08 AM
There is another interesting item I didn't know that the assembly constants were 16 bits. Also I always thought that zero should be false. It is easier to remember that false is nothing. Mike

KC9UDX
March 3rd, 2017, 10:12 AM
There is another interesting item I didn't know that the assembly constants were 16 bits. Also I always thought that zero should be false. It is easier to remember that false is nothing. Mike

The reason I normally use zero for true is that when comparing two numbers by subtraction or logical AND, there's no conversion. Equal is true and unequal is false.

Chuck(G)
March 3rd, 2017, 10:22 AM
Again, a matter of semantics. JNE is the same as JNZ in 8086 assembly. Similarly JB is the same as JC--if you're subtracting, it's convenient to think of a borrow; when adding, it's convenient to think of a carry.

Whatever floats your boat--as long as you make your intentions clear in the commentary!


.model tiny,syscall
0000 .code

org 100h

0100 Plough:
0100 74 FE je Plough
0102 74 FC jz Plough
0104 75 FA jne Plough
0106 75 F8 jnz Plough
0108 72 F6 jb Plough
010A 72 F4 jc Plough
010C 73 F2 jnb Plough
010E 73 F0 jnc Plough
0110 73 EE jae Plough

end Plough