In: Computer Science
Translate the following tasks into Hack C-Instructions:
1) Set D to A - 1 |
|
2) Set both A and D to A + 1 |
|
3) Set D to 19 |
|
4) Set both A and D to A + D |
|
5) Set RAM[5034] to D - 1 |
|
6) Set RAM[543] to 171 |
|
7) Add 1 to RAM[7], and store result in D |
|
8) Add 3 to RAM[12], and store result in D |
Hack C-Instructions has the following syntax dest = comp ; jump // dest ,= and jump mp are optional
Where: comp = 0 , 1 , ‐1 , D , A , !D , !A , ‐D , ‐A , D+1 , A+1 , D‐1, A‐1 , D+A , D‐A , A‐D , D&A , D|A, M , !M , ‐M , M+1, M‐1 , D+M, D‐M, M‐D, D&M, D|M
dest = M, D, A, MD, AM, AD, AMD, or null
jump = JGT , JEQ , JGE , JLT , JNE , JLE , JMP, or null
1) Set D to A - 1
Ans:: D = A-1
2) Set both A and D to A + 1 |
AD=A+1 |
3) Set D to 19 |
@19 //A=19 D=A //D=A=19 |
4) Set both A and D to A + D |
AD=A+D // AD means both A and B |
5) Set RAM[5034] to D - 1 |
@5034 //A=5034 M=D-1 //M=RAM[5034] =D-1 , Note M=RAM[A] |
6) Set RAM[543] to 171 |
@171 // A=171 D=A //D=171 @543 //A=543 M=D // M==RAM[A]=RAM[543]=D, RAM[543]=171 |
7) Add 1 to RAM[7], and store result in D |
@7 //A=7 D=M+1 //D=RAM[A] +1=RAM[7] +1 |
8) Add 3 to RAM[12], and store result in D @3 // A=3
D=A //D=3
@12 //A=12
D=D+M //D=D + RAM[A]=D+RAM[12] =3 +RAM[12]