mov M,#lit and best way of IF...THEN in SASM
Two questions here:
1) In SASM the instruction mov M,#lit will mov the # into the M register's lower 4 bits (SX28). But in the Example in the SxUsersManual, it says "mov M,#lit controls the four lower bits of the MODE register. The two subsequent “mov M,#lit” instructions change the lower four bits of the MODE register."
What is the difference between using mov M,#lit and mov W,#lit then mov M,W?
2) What is the best method of doing an IF...THEN condition in SASM?
I want to say:
IF RB.0 =1 AND RB.1 = 1 THEN jmp....
I need to use jb, and/or jnb, right?
Thanks, Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Mag748) : 1/7/2005 12:47:23 PM GMT
1) In SASM the instruction mov M,#lit will mov the # into the M register's lower 4 bits (SX28). But in the Example in the SxUsersManual, it says "mov M,#lit controls the four lower bits of the MODE register. The two subsequent “mov M,#lit” instructions change the lower four bits of the MODE register."
What is the difference between using mov M,#lit and mov W,#lit then mov M,W?
2) What is the best method of doing an IF...THEN condition in SASM?
I want to say:
IF RB.0 =1 AND RB.1 = 1 THEN jmp....
I need to use jb, and/or jnb, right?
Thanks, Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Mag748) : 1/7/2005 12:47:23 PM GMT
Comments
In the case of the SX28 there is no difference between MOV M,W and MOV W,#lit then MOV M,W.
However, in the SX48/52 this is not the case as these use the lower 5 bits, and the MOV M,W instruction only deals with the lower 4 bits.
As to your other question I'm not sure.
Peter
MOV W,RB ; Get bits
AND W,#3 ; Isolate bits
XOR W,#3 ; Invert bits
JZ label ; Jump if inverted bits were both zero
bean.
That's true, but is there any difference between mov M,#lit and mov W,#lit THEN mov M,W
Bean, thank you, I will try that.
Thanks, Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
In the SX28 there are only 8 modes, so 4 bits are enough. The Mode instruction (MODE literal) and Mov M,#lit only
move the lower 4 bits of a byte into the Mode register. The upper bits are ignored.
Now in the case of the SX48/52, there are many more modes and 5 bits are required. However, If you used the
MODE literal instruction as you did with the SX28, only 4 bits would be transferred, the 5th bit would be lost.
Therefore, you must use Mov W,#lit then Mov M,W to move all eight bits into the Mode register. Although the
upper 3 bits are ignored.
With SX28:
Use MODE Literal
Or Mov M, #lit
Or Mov W,#lit followed by Mov M,W
With SX48/52:
Use Mov W,#lit followed by Mov M,W
Dave G
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
sb rb.1
skip
jmp ...
If you stare at that for a while it will make sense... probably. It still confuses the heck out of me. This is the area where SX/B, SX/C, etc... really make a difference. In fact, it would be very interesting to see what they compile for the above line. But no time right now... I have to get back to the newsletter I'm writing on how to master SASM macros...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
mov w, rb
and w, #$03 ;mask the bits we are intersted in (2 lowest)
xor w, #$03 ;this is a backhanded equality operation
jnz :false ; if result is not zero then last two bits are not 1
;code for true condition
:false ....
explanation in a nutshell: if you take your test variable and XOR it with the value you are looking for, the result will be 0 if and only if the test variable is equal to the value ($03 xor $03 = $00, $02 xor $03 = $01, $00 xor $03 = $03 etc) you can use this technique for any number of bits in the same register and comparing it with any value. If you have "don't care" bits in the variable your testing (bits you are not testing) mask the test variable before XORing it by ANDing the·variable with a value where a binary 1 for that bit means we're testing it, 0 means we're not.
Hope this helps,
Paul
PS James' algorithm and mine take the same number of program words and take the same amount of time (4 cycles for a false, 6 cycles for a true), if you're testing 3 or more bits, my algorithm will be faster and occupy less code space (since mine always consumes 4 program words and takes 4/6 cycles regardless of the number of bits (well testing 8 bits drops it to 3 program words and·3/5 cycles·since you don't need the·AND but thats not the point)).
Post Edited (Paul Baker) : 1/8/2005 12:32:00 AM GMT
Also, the skip, jump only version preserves W and the status register.
Also, it is not limited to bits in the same byte.
For 3 or more bits, the and xor jmp is probably the only reasonable answer.
This is a classic case where macros can be written to use conditional assembly and always compile the best code without requiring the programmer to remember all this junk. e.g.
testbits macro
IF \0·=·2
· snb \1
· sb \2
· skip
· jmp
· ENDIF
IF \0 > 2
· REPT
and so on...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!