Docsity

AARCH64 Assembly Language: Performing Arithmetic and Defining Global Data, Study notes of Architecture

Partial preview of the text

Download AARCH64 Assembly Language: Performing Arithmetic and Defining Global Data and more Study notes Architecture in PDF only on Docsity!

Assembly Language:

Part 1

Princeton University

Computer Science 217: Introduction to Programming Systems

First half of the semester: “Programming in the large”

Second half: “Under the hood”

Context of this Lecture

Starting Now Later

C Language

Assembly Language

Machine Language

Application Program

Operating System

Hardware

language levels tour

service levels tour

Agenda

Language Levels

Architecture

Assembly Language: Performing Arithmetic

Assembly Language: Load/Store and Defining Global Data

High-Level Languages

Characteristics

  • Portable
    • To varying degrees
  • Complex
    • One statement can do much work – good ratio of functionality to code size
  • Human readable
    • Structured – if(), for(), while(), etc.

count = 0;

while (n>1)

{ count++;

if (n&1)

n = n*3+1;

else

n = n/2;

Assembly Languages

Characteristics

  • Not portable
    • Each assembly lang instruction maps to one machine lang instruction
  • Simple
    • Each instruction does a simple task
  • Human readable (In the same sense that Polish is human readable, if you know Polish.)

ands wzr, w0, # beq else

b endif else:

endif:

asr w0, w0, 1

add w2, w0, w add w0, w0, w add w0, w0, 1

add w0, w0, #

loop: cmp w0, 1 ble endloop

b loop endloop:

mov w1, 0

Why Learn Assembly Language?

Q: Why learn assembly language?

A: Knowing assembly language helps you:

  • Write faster code
    • In assembly language
    • In a high-level language!
  • Write safer code
    • Understanding mechanism of potential security problems helps you avoid them – even in high-level languages
  • Understand what’s happening “under the hood”
    • Someone needs to develop future computer systems
    • Maybe that will be you!
  • Become more comfortable with levels of abstraction
    • Become a better programmer!

Agenda

Language Levels

Architecture

Assembly Language: Performing Arithmetic

Assembly Language: Load/Store and Defining Global Data

John Von Neumann (1903-1957)

In computing

  • Stored program computers
  • Cellular automata
  • Self-replication

Other interests

  • Mathematics
  • Inventor of game theory
  • Nuclear physics (hydrogen bomb)

Princeton connection

  • Princeton Univ & IAS, 1930-

Known for “Von Neumann architecture (1950)”

  • In which programs are just data in the memory
  • Contrast to the now-obsolete “Harvard architecture”

Von Neumann Architecture

RAM

Control Unit

CPU

Registers

Data bus

ALU

RAM (Random Access Memory)

Conceptually: large array of bytes (gigabytes+ in modern machines)

  • Contains data (program variables, structs, arrays)
  • and the program!

Instructions are fetched from RAM

Von Neumann Architecture

RAM

Control Unit

CPU

Registers

Data bus

ALU

Registers

Small amount of storage on the CPU (tens of words in modern machines)

  • Much faster than RAM
  • Top of the “storage hierarchy”: above RAM, disk, etc.

ALU (arithmetic+logic unit) instructions operate on registers

Registers (ARM-64 architecture)

x0 (^) w

63 31 0

x1 (^) w

x29 (FP) (^) w x30 (LR) (^) w

xzr (all zeros) (^) wzr sp (stack pointer)

pc (program counter)

n z c v pstate

General-Purpose Registers

X0 .. X

  • 64-bit registers
  • Scratch space for instructions, parameter passing to/from functions, return address for function calls, etc.
  • Some have special purposes defined in hardware (e.g. X30) or defined by software convention (e.g. X29)
  • Also available as 32-bit versions: W0 .. W

XZR

  • On read: all zeros
  • On write: data thrown away

PC Register

Special-purpose register…

  • Contains PC (Program Counter)
  • Stores the location of the next instruction
    • Address (in TEXT section) of machine-language instructions to be executed next
  • Value changed:
    • Automatically to implement sequential control flow
    • By branch instructions to implement selection, repetition

PC

TEXT section

PSTATE Register

Special-purpose register…

  • Contains condition flags: n (Negative), z (Zero), c (Carry), v (oVerflow)
  • Affected by compare ( cmp ) instruction
    • And many others, if requested
  • Used by conditional branch instructions
    • beq , bne , blo , bhi , ble , bge , …
    • (See Assembly Language: Part 2 lecture)

n z c v pstate