05-14-2013, 09:17 PM
slenkar Wrote:im trying to learn assembly, but keep getting strange resultsProbably. From one basic instruction to another, *everything* can be destroyed in assembler (registers, etc).
this program for exampleQuote:function FASTCALL downone() as ubyte
asm
INC HL
end asm
end function
function FASTCALL setup() as ubyte
asm
LD HL,16384
end asm
end function
'LD B,0
function FASTCALL drawthis() as ubyte
asm
LD A,128
LD (HL),A
end asm
end function
Dim res as String
setup()
for x=0 to 100
downone()
drawthis()
next
this is supposed to draw something to the screen 100 times
is the for next loop interfering with the assembly?
ZX Basic uses memory (stack) to store temporary results from one instruction to another, but sometimes it realizes that two basic instructions together can be "operated" as a single instruction. And again, this new instruction can be packed with the next one as a single instruction, and so on. But once you insert an ASM block, this optimization is stopped.