Author Topic: Vm instruction times table  (Read 580 times)

cvirus

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Vm instruction times table
« on: June 09, 2016 »
Code: [Select]
set window 0,0,640,480
wln "Lets try to use the VM instructions"
    cnt = 10
    s = 0
    i = 1
    tab = 1
@start:
    MOV s 1
    MUL s i
    wln str$(tab)+" X "+str$(i) +" = "+str$(s)
    ADD i 1
    ADD s 0
    CMP i cnt
    ADD i 0
    JLE start
    JG exit
@exit:
wln "Count is over old chap"
wait keydown
end

Hey Marcus, how can i do it untill 10 not just 1?

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 541
    • View Profile
Re: Vm instruction times table
« Reply #1 on: June 09, 2016 »
You mean print all x*y, whith x and y in [1..10]?

Code: [Select]
result
j = 1
@jStart:
set caret (j - 1)*64, 0
i = 1
@iStart:
MOV @0 j
MUL @0 i
MOV result  @0
wln j, "x", i, "=", result
ADD i 1
CMP i 10
JG iEnd
JMP iStart
@iEnd:
ADD j 1
CMP j 10
JG jEnd
JMP jStart
@jEnd:

wait keydown
.\\\opz

cvirus

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Vm instruction times table
« Reply #2 on: June 09, 2016 »
Well i'm not @ home so i can not test, but it looks ok, and way better than mine :-(, do you have a screen of the result?

Thanks

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 541
    • View Profile
Re: Vm instruction times table
« Reply #3 on: June 09, 2016 »
I've attached a screenshot  :D
.\\\opz

cvirus

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Vm instruction times table
« Reply #4 on: June 09, 2016 »
Dam, that is what i was looking to achieve, i was trying to do everything in the same loop :-).

Thanks

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 541
    • View Profile
Re: Vm instruction times table
« Reply #5 on: June 09, 2016 »
Using global variables are just as fast as using the registers [@0 .. @7]. If you're doing VM code inside a subroutine the register are faster than the local variables and parameters though.

Haha, I only added the VM commands to be able to make the Raycaster fast enough  :))
.\\\opz

cvirus

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Vm instruction times table
« Reply #6 on: June 09, 2016 »
but in the docs says that we can only use from @0 to @4, this means that we can use to @7? 8 all registers? Damn, what about memory allocation is it possible too?

Thanks :-)

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 541
    • View Profile
Re: Vm instruction times table
« Reply #7 on: June 10, 2016 »
The docs are probably right  O0 

Nah, no way to allocate memory, the small selection of instructions are just there to speed up algorithms/calculations :)
.\\\opz