Author Topic: Few questions concerning VM-instructions  (Read 478 times)

Hemulius

  • Newbie
  • *
  • Posts: 4
    • View Profile
Few questions concerning VM-instructions
« on: August 18, 2015 »
Hi!
I´ve recently found NaaLaa and I think it is pretty neat. After studying and writing some experiments with it, I have come up with few questions and I couldnt find answers from earlier posts, so here we go...

1. In demos\examples\TGA, there is a line of code "dst[1] = ((p[1 + offset] AND 0x03) SHL 6) OR ((p[0 + offset] AND 0xe0) SHR 2)". How command OR actually works in this sentence?
 
2. In mode7 and raycaster code there are few references to usage of register @5. If I´m not using either library, can register @5 be used safely along with @0-@4?

3. What´s the difference between STP or STP#? Is it because of array contains floats or is there occurrences when array index can be a fraction and will be rounded?

4. In documentation VM section, "what about floating points?" It says "with some tweaking you can put floats on stack aswell". Is it just a metaphor or what is this required tweaking exactly?

5. Is there any way to see generated VM code before it´s compiled, or can it be saved as a separate text file? Would be very helpful to study programs and possibly discover features that might be usefull.


Michael Abrash says in his Graphics Programming Black Book following: "Comment your code, design it carefully, and write non-time-critical portions in a high-level language, if you wish - but when you write the portions that interact with the user and/or affect response time, performance must be your paramount objective, and assembly is the path to that goal."

It is over two decades old wisdom, but it is still valid and I have fallen in love with NaaLaa because of it´s combination of both, high-level language and VM-instructions.

Keep up the good work!

Rick3137

  • Sr. Member
  • ****
  • Posts: 347
  • May the Force be with You
    • View Profile
    • Rick's Programs
Re: Few questions concerning VM-instructions
« Reply #1 on: August 24, 2015 »
    The OR and the AND in question # 1 are logical statements that I normally use in "if" statements. I don't think NaaLaa uses the other type of and/or logic.  I use NaaLaa when I feel too lazy to do hard languages like C++ ( most of the time) The rest of the code in that example is mainly Greek to me.
   My personal usage runs more like this: if a > 10 and  b < 20 then c = 30

Hemulius

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Few questions concerning VM-instructions
« Reply #2 on: August 27, 2015 »
Code: [Select]
wln "Value 0x0ff is hexadecimal representation of value " + str(0x0ff)
wln "You can use fixed-point math with hex-values and"
wln "bit-shifting commands SHL and SHR, but NaaLaa is so fast in"
wln "floating point calculations so there is no need to get into that."
wln
wln "In conditional statements, notice the difference between 'and' compared to 'AND'"
wln "This compiles: if ((10 > 9) and (9 < 11))"
wln "This wont:     if ((10 > 9) AND (9 < 11))"
wln
if ((10 > 9) and (9 < 11))
wln "This logic is straightforward"
wln "1 OR 1 = " + str(1 OR 1)
wln "1 OR 0 = " + str(1 OR 0)
wln "0 OR 1 = " + str(0 OR 1)
wln "0 OR 0 = " + str(0 OR 0)
wln "1 AND 1 = " + str(1 AND 1)
wln "1 AND 0 = " + str(1 AND 0)
wln "0 AND 1 = " + str(0 AND 1)
wln "0 AND 0 = " + str(0 AND 0)
wln
endif

if ((10 = 11) or (10 = 10))
wln "But it gets confusing if you replace ones and zeroes with something else"
wln "like in example: array[index] = something OR something"
wln
wln "10 OR 10 = " + str(10 OR 10)
wln "10 OR 7 = " + str(10 OR 7)
wln "7 OR 10 = " + str(7 OR 10)
wln "7 OR 7 = " + str(7 OR 7)
wln "10 AND 10 = " + str(10 AND 10)
wln "10 AND 7 = " + str(10 AND 7)
wln "7 AND 10 = " + str(7 AND 10)
wln "7 AND 7 = " + str(7 AND 7)
wln
endif

wait keydown
« Last Edit: August 27, 2015 by Hemulius »