Fill.asm

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Fill.asm

Theo
Hey guys,
So basically my logic for this is that if in Ram 24576 the number isn't 0, go to a loop that starts filling all Ram 16384 to (16384+8192) with -1. And vice versa. Problem is though that I can't figure out how to make a incremental loop for the Address. Like I don't know how to make it go to the next memory address and I feel like this could be something easy and I'm being a little stupid but yeah. I tried something along the lines of A = A+1 but this made the program jump to the Ath line in the .asm file somehow, I don't know why. Any help would be of great help. Thank you :)
Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm

cadet1620
Administrator
If you haven't done Mult.asm yet, you should do it first.  You will learn how to do a simple loop without the complication of reading the keyboard.  Note that the numbers used in Mult.tst are small so you can multiply by repeated addition.

If A=A+1 is causing a jump to the new A value, you might be misunderstanding how jumps work.  They always jump to the value in A, so a jump takes two instructions:
    @target
    0;JMP
Since the target address must be in A, only computations involving D are useful for conditional jumps.

Read 4.2.4, there are built-in symbols you can use for the screen and keyboard. Using these symbols instead of numbers will make your program more readable.

If you become a registered forum member, you can send me mail and I will be able to give you more detailed help off forum.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm

theo p
This post was updated on .
Hey man, yeah i have already done Mult.asm and it was alright, the difference is that I don't exactly know on the fill.asm how to get it to loop right through the memory addresses, like I don't know how to make it jump all through the memory addresses because you can't use let's say A = A - 1 or something (because that jumps to the instruction memory for some reason)
Here's my mult.asm:

[Source code removed by admin.]

Thanks a lot btw :)
Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm

Chuck Bartowski
This post was updated on .
Hello!
I have the same problem as you mate. Could You tell me how did you resolved that problem? My only ideas to increment the loop is A=A+1 and something like D=A    D=D+1      A=D, but this doesn't work.
Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm

cadet1620
Administrator
Chuck Bartowski wrote
Hello! I have the same problem as you mate. Could You tell me how did you resolved that problem? My only ideas to increment the loop is A=A+1 and something like D=A D=D+1 A=D, but this doesn't work.
You need to use variables in memory. The A-register in the Hack Computer is used for both addresses and constants so there is no way to keep a value in the A-register during a loop.

When you wrote Mult.asm, the R# "registers" are really memory variables with those names. For Fill.asm, just start using a variable and the assembler will assign it a unique address.

A program to fill addresses 100 to 199 with 55 might look like this:

// Initialize pointer to 100
    @100
    D=A
    @pointer
    M=D

(LOOP)
// Set memory at pointer to 55
    @55
    D=A
    @pointer
    A=M
    M=D

// Increment pointer and repeat loop if it's not 200
    @pointer
  [needs some code here]
    @LOOP
    D;JLT

// Halt
    @HALT
(HALT)
    0;JMP
Try to figure the increment and compare code yourself. If you need more help, send me a private message (More|Reply to author) and I can help you off forum.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm

Chuck Bartowski
Thanks cadet1620 for your help. I figure out that variable address go back to its default value, after we change the variable. For example:

@100
D=A
@variable1     \\ let say address of it is 19
A=D              \\ now the variable1 address is 100
@variable2
@variable1     \\ but now the address of variable1 goes back to 19, and i was pretty sure it is still 100

I hope this will help to somebody.
Sorry for my english.

Regards
Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm

cadet1620
Administrator
I think you are confusing the address of a variable and the value of a variable.

The address of a variable is assigned by the assembler and cannot be changed. You can load this program into the CPU simulator and step through it to see how it works.

// Here's how to set var1=123
    @123
    D=A     // 123 now in D-reg
    @var1   // ADDRESS of var1 in A-reg

// This is what sets the VALUE of var1 to 123
    M=D     // memory[A-reg] = D-reg

// The same sequence sets var2=456
    @456
    D=A
    @var2
    M=D

// Compute var3=var1+var2.
    @var1
    D=M
    @var2
    D=D+M
    @var3
    M=D

    @HALT
(HALT)
    0;JMP
For Fill.asm, you will need a variable whose value is the address of the screen location you want to change. A variable used this way is called a pointer.

To use a pointer variable, you need to load its value into the A-register. Then M will read or write using the address stored in the pointer.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm

theopavlakou
Thank you so much man! It's so great having helpful people like you on this forum, thank you so much :) 
On 13 Sep 2011, at 16:39, cadet1620 [via Questions and Answers Forum] wrote:

I think you are confusing the address of a variable and the value of a variable.

The address of a variable is assigned by the assembler and cannot be changed. You can load this program into the CPU simulator and step through it to see how it works.

// Here's how to set var1=123
    @123
    D=A     // 123 now in D-reg
    @var1   // ADDRESS of var1 in A-reg

// This is what sets the VALUE of var1 to 123
    M=D     // memory[A-reg] = D-reg

// The same sequence sets var2=456
    @456
    D=A
    @var2
    M=D

// Compute var3=var1+var2.
    @var1
    D=M
    @var2
    D=D+M
    @var3
    M=D

    @HALT
(HALT)
    0;JMP
For Fill.asm, you will need a variable whose value is the address of the screen location you want to change. A variable used this way is called a pointer.

To use a pointer variable, you need to load its value into the A-register. Then M will read or write using the address stored in the pointer.

--Mark


If you reply to this email, your message will be added to the discussion below:
http://questions-and-answers-forum.32033.n3.nabble.com/Fill-asm-tp3294712p3332622.html
To unsubscribe from Fill.asm, click here.

Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm

Chuck Bartowski
In reply to this post by cadet1620
Oh, i get it now.
A and D are registers not link with any variable. I was thinking only D can transfer values between variables, and A keeps address only of ACTIVE variable.

Thanks again pal.