teaching machines

CS 352 Lecture 24 – Memory and Branching

November 4, 2016 by . Filed under cs352, fall 2016, lectures.

Dear students,

Sometimes in the middle of a semester, we forget why we are here. Let’s step back a moment and check out what the ACM/IEEE Computer Science 2013 Curriculum has to say about computer architecture. Are we hitting upon any of the expected ideas?

Let’s then write some programs that will grow our understanding of the ARM architecture. In particular, we will start dealing with memory, and not just registers. This will require us to indirectly process data through addresses. An architecture like x86 makes it pretty easy to reference memory in most instructions, but ARM is what’s called a load/store architecture. Only these two instructions can deal with memory. The rest must operate on registers and immediates. We will also take a peek at branching.

We’ll explore these topics by writing programs that do the following:

See you next class!

Sincerely,

P.S. It’s Haiku Friday!

up, more, clap, uhoh
These were my first instructions
Now it’s getajob

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

flash.s

.text
.global main

main:
  push {lr}
  
  ldr r2, =operand2
  ldr r2, [r2]
  ldr r1, =operand1
  ldr r1, [r1]
  ldr r0, =message

  mul r8, r1, r2

  bl printf 

  // r1 = address of product
  ldr r1, =product
  ldr r0, =input_format
  bl scanf

  ldr r7, =product
  ldr r7, [r7]

  cmp r7, r8
  // we stopped here

  pop {lr}

  mov pc, lr

.data
input_format:
  .asciz "%d"

operand1:
  .word 4

operand2:
  .word 42

product:
  .word 134213

message:
  .asciz "%d * %d = "