CS 352 Lecture 16 – Hack Assembly Cont’d

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:

  • Store the twos complement of R0 in R1.
  • R4[R5] = R6.
  • Declare an array of five shorts with these contents: [R0 * 1, R0 * 2, R0 * 3, R0 * 4, R0 * 5].
  • R15 = R14 * 32.
  • Plot a sixteen-pixel line at beginning of row R14 in the SCREEN bitmap.

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

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *