So I'm working on my VM translator for project 7, and getting through the SimpleAdd was a breeze, but now that I'm trying the stack test, I'm running into an interesting error. I'm getting an error from the CPU Emulator saying "In line 274, Expression Expected", so I did some digging.
In the StackTest.vm, the following lines occur: push constant 57 push constant 31 push constant 53 add push constant 112 sub neg and but doesnt neg just give the negative value of the current constant? or am I misunderstanding what neg really means? I'm confused because and seems like an operation that can only be executed on true or false, as I have it set up to give, however, with non 0 or 1 constants, how does and work? Thanks 
Administrator

The CPU Emulator reads the ASM your translator generates. The error you are getting is because of a syntax problem in that ASM. The neg command is arithmetic negation. And, or and not commands are bitwise logical operations. That is, each individual bit in the word(s) are anded, ored, or notted. The commands push 255 // 0x00FF not result in 256 (0xFF00) on the top of the stack. Mark 
Ok, so it operates as I thought it would, except how do I get an integer negative of the current value? I tried
M=0M and I think that's where my syntax error is happening, can you help me? 
and and or are also confusing me when confronted with integer values.
how do i generalize how to "and" or "or" two integer values if not given them up front>? 
Administrator

This post was updated on .
In reply to this post by ngdrummer
M=M The ALU's "and" and "or" operations are bitwise and work just fine on integers. An example of when you might want to bitwiseand and or an integer is a trick I use in my minimal length Fill.asm to avoid having to compare and reset my screen pointer: p = 0x4000 // SCREEN forever { if key down *p = 1 else *p = 0 p = ((p+1) & 0x1FFF)  0x4000 }I use bitwise operations like this quite a bit when writing embedded system firmware. Mark 
ok, I get that the bitwise operators work fine, but I've never had to program bitwise operations in a high level language, so the notation #x#### is foreign to me, and I'm just trying to figure out how to represent the and operation or the or or not in assembly language, or high level language

I guess when it comes down to it I'm completely lost on how to do bitwise operations in assembly language...

OMG, & and  are actual symbols...I thought I was expected to write out arithmetic functions...life is awesome...wow

Administrator

In reply to this post by ngdrummer
ASM operations for bitwise and and or are, for example, D=D&M and D=DM.
0x12AB is hexadecimal notation which is a compact way of writing binary numbers. The digits are 09 and AF which represent the binary values 00001001 and 10101111 respectively. Sometimes it's written 12ABh. The AF and H and X can be written in either upper or lower case; it means the same thing. In my example, 0x4000 = 0100000000000000 = 16384 = SCREEN and 0x1FFF = 0001111111111111. Here's how the screen pointer "p = ((p+1) & 0x1FFF)  0x4000" statement works: The screen addresses are 0x4000  0x5FFF (0100000000000000  0101111111111111) when when p+1 becomes 0x6000  the first address beyond the screen  then: 0110000000000000 (p+1) 0001111111111111 AND  0000000000000000 0100000000000000 OR  0100000000000000 new p value: the beginning of screen address when p+1 is still withing the screen address range: 0101001110101001 (p+1) 0001111111111111 AND  0001001110101001 0100000000000000 OR  0101001110101001 new p value: (p+1) And can be thought of as selecting bits that we want to allow to be ones, and Or can be thought of as setting bits that we need to be on. Mark 
Thanks for all the help, I'm just totally dumb and forgot I was able to use & and  in assembly. I spent all this time trying to figure out a way to write in +,,JMP operations a bitwise and on integer values...
well, now that that's overwith, I'm stuck on this and that for push and pop in memoryvalues, hehe. 
Free forum by Nabble  Edit this page 