Why the topic? Why not?

I have a question:


Code:

EF4045
FDCB00AE
210000
22D7
8621A
C9D
EF0A45
EF2E45
C948656C6C6F
20776F726C64
2100


I originally wrote it in hexadecimal, it even had a problem, but Deep Thought found it. Eitherway, I tried to put this in mnemonics so I can get help:


Code:

  b_call(_ClrLCDFull)
  ld     HL, 0
  ld     (PenCol), HL
  ld     HL, msg
  b_call (_PutS)
  b_call (_NewLine)
  ret
msg:
    .DB "Hello world!", 0


What I'd like to know is how to have line breaks in text? So I could have in the output:


Code:

Hello,
World
!


I don't care if the answer is hex or asm, eitherway, I'll just make it hex Very Happy
You have to:
either put as many spaces in so that the lines become full
or you have to do it in 3 times:

Code:

msg1:
.db "hello,"
msg2:
.db "world"
msg3:
.db "!"

Its totally up to you, I would prefer method 1 here, because this is not so much text.
The most optimized one seems first:D Thanks.

EDIT:


Code:
.nolist
#include "ti83plus.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  b_call(_ClrLCDFull)
  LD     HL, 0
  LD     (PenCol), HL
  LD     HL, msg
  b_call(_PutS)        ; Display the text
  b_call(_NewLine)
  ret
msg:
    .DB "Hello           "
   .DB "World",0


How many chars has a line though?
16 characters per line. Why are you using Pencol and Puts together, though? Pencol/penrow go with _vputs (graphscreen text), while curcol/currow go with _puts (homescreen text).
KermMartian wrote:
16 characters per line. Why are you using Pencol and Puts together, though? Pencol/penrow go with _vputs (graphscreen text), while curcol/currow go with _puts (homescreen text).


Thanks! I didn't know about that. I also know I could use HomeUp to prepare the screen here but I don't know its hex code.
Why not just use bcall(_homeup), then? Razz And now you know about the text types. Curcol can be 0-15, Currow can be 0-7, for 16x8 homescreen characters. The graphscreen is 96x64, so pencol can be 0 to 95, and penrow can be 0 to 57 (text is 6 pixels tall!).
KermMartian wrote:
Why not just use bcall(_homeup), then? Razz And now you know about the text types. Curcol can be 0-15, Currow can be 0-7, for 16x8 homescreen characters. The graphscreen is 96x64, so pencol can be 0 to 95, and penrow can be 0 to 57 (text is 6 pixels tall!).


As I stated in the first post I'm not using mnemonics. I'll dig into that though, thanks!
The character $3F is a newline character, so you could use that. I'm not sure if it would work, though.
souvik1997 wrote:
The character $3F is a newline character, so you could use that. I'm not sure if it would work, though.
If I recall correctly, it would not, but that's some good outside-the-box thinking regardless. Smile Scout, if you insist on making life harder for yourself (in my opinion) and want to learn hEx-represented ASM, you can still mix in mnemonics. Smile
This is my code.


Code:
.nolist
#include "ti83plus.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL _ClrLCDFull
  ld a, 1
  cp 1                 ; If A = 1
  jr z, DisplayNumber1 ; A – 1 = 0. So, if A = 1, CP 1 will give A – 1 = 1 – 1 = 0, therefore the zero (Z) flag will be set
 
  cp 2
  ret z                ; If A = 2, end the program
 
DisplayNumber1:
  ld h, 0
  ld l, a              ; Remember that CP does not affect A. A still equals 1.
  B_CALL (_DispHL)
  B_CALL (_getKey)
  B_CALL (_ClrCLDFull)
  ret


I understand this code, cp 1 will set the zero flag, so, when we do 'jr z, DisplayNumber', since z is set it displays number 1.

My question is, in the end of the second label (DisplayNumber1) there's a 'ret', will it end the program or is it just like 'Return' in the soubrutine and go back to the main code (Init) where it was left.

I think it goes back to:


Code:

cp 2
ret z


And this is what I don't get.

a is 1, if we do "cp 2", then we set the Carry flag, not the zero flag. So why does "ret z" work?

Thanks.
The ret will end the program, since you are not calling that piece of code as a subroutine. Also, as you said, the cp 2 \ ret z will not ever get executed since a is 1 and you are jumping to DisplayNumber1.
souvik is right: it doesn't even look at the cp 2 / ret z part. one way to test out what would happen is to XOR A before the first cp and then do the ld a, 2.

If it helps at all, this is how it would be read, like a pseudocode program:


Code:
A == 1
If A=1
 Goto DisplayNumber
ElseIf A == 2
 Return;
End
souvik1997 wrote:
The ret will end the program, since you are not calling that piece of code as a subroutine. Also, as you said, the cp 2 \ ret z will not ever get executed since a is 1 and you are jumping to DisplayNumber1.


Thanks a lot.

@Ashbad:


Code:
A == 1
If A=1
 Goto DisplayNumber
ElseIf A == 2
 Return;
End


Thanks much, it makes sense Smile
yeah, I've learned that pseudocoding or writing something in axe first helps me understand what I'm trying to do, then I use that to translate it into assembly Wink
I just learnt we can use increment loops in Assembly too Very Happy


Code:
 
  ld a,0
 
Increase_A_Until_A_Is_Strictly_Greater_Than_30:
  inc a
  cp 31
  jr c, Increase_A_Until_A_Is_Strictly_Greater_Than_30
indeed we can Smile which is very useful Wink

in case you do not know how decrement loops work:


Code:
   XOR A
   LD B,150
Loop
   INC A
   DJNZ Loop
End


This will keep going until B == 0, and at that end, A will be equal to 150 Wink DJNZ loops are very commonly used, but the type of loop depends on the purpose you're after.
Ashbad wrote:
indeed we can Smile which is very useful Wink

in case you do not know how decrement loops work:


Code:
   XOR A
   LD B,150
Loop
   INC A
   DJNZ Loop
End


This will keep going until B == 0, and at that end, A will be equal to 150 Wink DJNZ loops are very commonly used, but the type of loop depends on the purpose you're after.


xD Ashbad, of course I know how those loops work, and there's an error in that code:

Loop:

Eitherway, what does "xor a" do? I would ld a,0.
XOR A is a simple way of doing LD A,0 -- however it's the most optimized version, faster and smaller than LD A,0 and AND 0. Wink

and, I use brass for labels, so I use no colons.
Ashbad wrote:
XOR A is a simple way of doing LD A,0 -- however it's the most optimized version, faster and smaller than LD A,0 and AND 0. Wink

and, I use brass for labels, so I use no colons.


I don't like labels, they don't exist in hexadecimal, or at least we don't have to set them. In hex we do like:


Code:
Code
Code
Code (this code is part of my label but I don't need to say it is)
Code (code of the label)
Jr (to jump back to the beginning of the label, I set here where the label starts) (also jr is 18)


What doex xor a do to a if a already has a value?

Let's say:


Code:

ld a,10
xor a


xor a:


Code:
[Z80] Instruction \ Main: xor reg8 \ Instance: xor a [AF] \ Bytes: 1 \ Cycles: 4/7 \ Flags: SZ-0-P00 \ Description: Bitwise XOR on a with reg8.
it sets A to zero Wink basically, XOR works by comparing A to another value in an xor bitwise comparision -- which can work like this:

Basically, xor takes two values, and checks them bit by bit. It compares to see if two corresponding bits are both the same -- if so, the returned bit for that position is zero. It only returns a 1 for that bit if only one of the bits are set Wink

and scout, there's little point of using a mnemonic assembler if you don't use labels -- labels is one of the main points of an assembler Razz
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
» View previous topic :: View next topic  
Page 1 of 10
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement