teaching machines

CS 352 Lecture 16 – Hack Assembly Cont’d

October 13, 2016 by . Filed under cs352, fall 2016, lectures.

Dear students,

Today we continue discuss low-level ideas of assembly language using Hack. We start with a little number I like to call What Does This Do. I will show some code, which you should read any mentally evaluate. After a few moments, we’ll discuss.

WDTD #1
@R0
D=M
@R1
M=D
@R0
D=M
@R1
M=D+M
WDTD #2
@R6
D=M
@FOO
M=D
@R7
D=M
@R6
M=D
@FOO
D=M
@R7
M=D

Then let’s work through some more assembly exercises together:

Remember, no class on Friday! I’m at a Code.org workshop.

See you next class!

Sincerely,

P.S. It’s Haiku Wednesday!

Assembly is like…
The day before groceries
Marriage, pre-money

P.S. Here’s the code we wrote together:

Twos.asm

@R0
D=!M
D=D+1
@R1
M=D

Index.asm

// Load base pointer.
@R4
D=M

// Load offset.
@R5
D=D+M

// Make temporary.
@TMP
M=D

// Load up the RHS.
@R6
D=M

@TMP
A=M
M=D

Multiples.asm

@V
@W
@X
@Y
@Z

@R0
D=M

@V
M=D

@R0
D=D+M

@W
M=D

@R0
D=D+M

@X
M=D

@R0
D=D+M

@Y
M=D

@R0
D=D+M

@Z
M=D

@R0
D=D+M