CPSC355 studying

0.0(0)
studied byStudied by 7 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/174

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

175 Terms

1
New cards
A basic computer system consists of:
Central Processing Unit (CPU)

System Clock

Primary Memory

Secondary Memory

Peripheral devices

Bus
2
New cards
What is the the purpose of the CPU?
Executes instructions

Controls the transfer of data across the BUS
3
New cards
What are the 3 main parts of the CPU?
Control Unit (CU)

Arithmetic Logic Unit (ALU)

Registers
4
New cards
What is the Job of the CU?
- Directs the execution of instructions
5
New cards
What is the Job of the ALU?
Preforms arithmetic and logical operations on data stored in registers
6
New cards
What are Registers?
Are binary storage units within the CPU
7
New cards
What are general-purpose registers?
Used to temporarily hold data and addresses
8
New cards
The Program Counter(PC)?
Contains the address in memory of the currently executing instruction
9
New cards
The Status Register?
Contains information(flags) about the results of a previous instruction
10
New cards
What is the System Clock?
Generates a clock signal to synchronize the CPU and other clocked devices

iMac(2016) - 3.2 GHz

Raspberry Pi - 700 MHz
11
New cards
What is Primary Memory?
Is Random Access Memory that is volatile and is used to store program instructions and program data
12
New cards
What is a Bus?
Is a set of parallel data/signal lines used to transfer information between computer components
13
New cards
3 types of Bus?
Address Bus - Specifies memory location in RAM

Data Bus - Used for bidirectional data transfer

Control Bus - Used to control or monitor devices connected to the bus
14
New cards
What is Secondary Memory?
Is used to hold a computer's file systemIs non-volatile read/write memory

Usually embodied on a hard disk drive (HDD)
15
New cards
What are peripheral I/O Devices?
Allow communication between the computer and the external environment
16
New cards
Examples of input Devices
Keyboard

Pointing devices

Microphone

Scanner
17
New cards
Examples of output devices
Monitior

Printer

Speakers
18
New cards
Examples of I/O devices
HDD

Modem

Connection to networks
19
New cards
Where do operands for an instruction come from?
The accumulator register (ACC) and from a single location in RAM
20
New cards
What is the typical program sequence?
\-Load registers from memory

\-Execute an instruction using two source registers, putting the result into a destination register

\-Store the result back into memory
21
New cards
What is a RISC architecture
Reduced Instruction Set Computer

* Uses only simple instruction that can be executed in one machine cycle
* Machine instructions are always the same size
* Enables faster clock rates, thus faster overall execution
* Makes programs larger and more complex
* Makes decoding simpler and faster
22
New cards
What is a CISC architecture?
May have instructions that take many cycles to execute

* Provided for programmer convenience
* Slows down overall execution speed
* Machine instructions vary in length and may be followed by immediate data
* makes coding difficult and slow
23
New cards
What is an Instruction Cycle?
Also called the fetch-execute or fetch-decode-execute cycle


1. Fetch the next instruction from memory into the IR
2. Increments PC to point to the next instruction
3. Decode the instruction
4. If the instruction uses an operand in RAM, calculate its address
5. Fetch the operand(4 and 5, repeat if necessary)
6. Execute the instruction
7. If the instruction produces a result that is stored in RAM, calculate its address

(6 and 7, repeat necessary)


8. Store the result
24
New cards
What is the basis of Assembly Language Programs?
\-Consists of a series of statements, each corresponding to a machine instruction

\- Each statement consists of an opcode and a variable number of operands
25
New cards
What are assemblers?
Translate assembly source code into machine code
26
New cards
What are macro processors
Assemblers that can support macros where you can define a piece of text with a macro name
27
New cards
What type of Computer is the ARMv8-A architecture?
- Is a RISC- Is a Load/Store machine
28
New cards
The ARMv8-A architecture has two execution states
* AArch64
* AArch32
29
New cards
The ARMv8-A has 4 exception levels
EL0: for normal user applications with limited privileges

\- Restricted access to a limited set of instructions and registers

EL1: for the OS kernel

\- Privileged access to instructions, registers, and memory

EL2: for a Hypervisor

\- Support virtualization, where the computer hosts multiple guest operating systems, each on its own virtual machine

El3: Low-level firmware

\- Include the Secure Monitor
30
New cards
How many registers in AArch64?
31 64-bit wide general-purpose registers, labeled x0-x31
31
New cards
What are registers x0-x7 used for?
Used to pass arguments into a procedure and return results
32
New cards
What is register x8 used for?
Indirect result location register
33
New cards
What are registers x9-x15 used for?
Temporary registers
34
New cards
What are registers x16-x17 used for?
intra-procedure-call temporary registers
35
New cards
What are registers x18, x29, and x30 used for?
x18: Platform register

x29: Frame Pointer

x30: Procedure Link register
36
New cards
What registers are used as callee-saved registers?
X19-X28
37
New cards
What are the three special-purpose registers?
* Stack Pointer: (SP) Used to point to the top of the run-time stack
* Zero Register: (XZR) gives 0 value when read from, discards value when written to you
* Program Counter: (PC) holds the address of the currently executing instruction
38
New cards
What is the form of the move instruction?
32 bit immediate
mov Wd, \#imm32
32 bit register
mov Wd, Wn
64 bit immediate
mox Xd, \#imm64

64 bit register
mox Xd, \#imm64
39
New cards
How can functions be called?
Using the Branch and Link Instruction (bl)
40
New cards
What is the basis of a main routine in an Assembly Language Program
.global mainmain: stp x29, x30, [sp, 16]! (These 3 are save states) mov x29, sp

Code here
ldp x29, x30, [sp], 16 (These two are restore states)ret
41
New cards
What does the ".global main" do?
- Makes the label "main" visible to the linker- The main() is where execution always starts
42
New cards
What does "[sp,16]!" mean?
Allocations 16 bytes in stack memory (in RAM)
43
New cards
What does "stp x29, x30" mean?
Stores the contents of the pair of registers to the stack
44
New cards
"mov x29, sp"
- Update FP to the current SP- FP may be used as a base adress in the routine
45
New cards
"ldp x29, x30, [sp], 16"
- Loads the pair of registers from RAM- Restores the STate of the FP and LR registers
- Deallocated 16 bytes of stack memory
46
New cards
Addition
add x20, x19, x21
x20 = x19 + x21
47
New cards
Multiplication
mul x20, x19, x21
x20 = x19 * x21
48
New cards
Subtraction
sub x20, x19, x21
x20 = x19 - x21
49
New cards
Multiply-Add
madd Wd, Wn, Wm, Wa
Wd = Wa + (Wn * Wm)
50
New cards
Multiply-Subtract
msub Wd, Wn, Wm, Wa
Wd = Wa - (Wn * Wm)
51
New cards
Multiply-Negate
mneg Wd, Wn, Wm
Wd = -(Wn*Wm)
52
New cards
Division
Signed form
sdiv Wd, Wn, Wm
Wd = Wn/Wm
Unsigned form
udiv Wd, Wn, Wm
Wd = Wn/Wm
53
New cards
How to print to standard Output
fmt: .string "This is a string"

adrp x0, fmt

add x0, x0, :lo12:fmt

bl printf
54
New cards
What is a branch instruction?
A branch instruction transfers control to another part of a program
55
New cards
What are Condition flags?
Are single-bit units in the CPU, record process state information, 0 means false and 1 means true
56
New cards
What are the 4 condition flags?
Z: true if result is Zero

N: true if result is Negative

V: true if result is overflows

C: true if result generates a carry out
57
New cards
How can you set condition flags?
Are set by instructions that end in "s" (short for set flags)
Eg, subs, adds
58
New cards
Table for Conditions
NAME MEANING C Equivalent Flagseq equal == Z==1ne not equal != Z==0gt greater than > Z==0 && N==Vge gt or equal >= N==Vlt less than < N!=Vle lt or equal
59
New cards
How are loops formed?
They are done by branching from the bottom of the loop to the top
60
New cards
Example of do loop
define(x_r, x19)
mov x_r, 1 top: statements forming loop body
add x_r, x_r, 1 cmp x_r, 10 b.le top
61
New cards
Example of while loop
define(x_r, x19)
mov x_r, 0 test: cmp x_r, 10 b.ge done

statements forming body of loop

add x_r, x_r, 1 b test
62
New cards
Example of for loop
define (i_r, x19)

define (x_r, x20)

mov i_r, 10 // initialization

b test

top:

add x_r, x_r, i_r

// loop body

add i_r, i_r, 1

// increment

test:

cmp i_r, 20

// if i < 20 ..

b top

// branch to b (do ..)
63
New cards
What is the if Construct?
Is formed by branching over the statement body if the condition is not true
64
New cards
Example of If-Else Construct
o Eg: C code if (a > b) { c = a + b; d = c + 5; }

In assembly:

define (a_r, x19)

define (b_r, x20)

define (c_r, x21)

define (d_r, x22)

. . .

cmp a_r, b_r

//test

b.le next

// logical complement
add c_r, a_r, b_r

// body

add d_r, c_r, 5

next:

statement after if-construct
65
New cards
What are binary numbers?
Are base 2 numbers

Use only the binary digits (bits) 0 and 1

Easy to encode on a computer

An N-bit register can hold 2^N bit patterns
66
New cards
How are unsigned integers encoded?
Using only binary numbers, range is 2^N - 1, where N is the number of bits
67
New cards
How are signed integers encoded?
- Most commonly encoded using the two's complement representation
Range: -2^N-1 to +2^N-1 -1
Negating a number is done by: - Taking the one's complement - Adding 1 to the result
- All positive numbers will have a 0 in the left-most bit- All negative numbers will have a 1 in the left most bit
68
New cards
What are hexadecimal Numbers?
Are base 16 numbers
0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 A 1010 B 1011 C 1100 D 1101 E 1110 F 1111

* 0xF5A
69
New cards
What are Octal Numbers?
Are base 8 numbers
70
New cards
Different types of data table
A64 Keyword Size in Bits C Keyword byte 8 char halfword 16 short int word 32 int doubleword 64 long int, void \*(pointer)quadword 128 N/A
71
New cards
What are bitwise logical instructions?
Manipulate one or more bits in a register
72
New cards
AND
is used for making bitmasks

* E.g ANDing with 1111 0000 (0xF0) sets bits 0-3 to 0, but keeps the rest the same
73
New cards
ORR
can help you set bits (put a 1 for the bits you want to set)

E.g 1010 1010

orr 0011 0000

1011 1010
74
New cards
EOR
helps to toggle bits

* E.g put a 1 in the position of the bits you want to switch 0101
* eor 1111
* 1010
75
New cards
Bit Clear (AND NOT)
allows you to clear bits

* E.g set a 1 in the position of a bit you would like to set to 0
76
New cards
What is a logical shift left?
Whenever you would like to shift the bits to the left or multiply by a power of two
Form: lsl Xd, Xn, Xm
77
New cards
What is logical shift right?
Form: lsr Xd, Xn, Xm
Whenever you would like to shift bits to the right or divide by a power of two
No remainder
Does not work for negative signed integers
78
New cards
What is Arithmetic Shift Right?
Form: asr Xd, Xn, Xm
Xn: bit pattern to be shiftedXm: shift count
ASR preserves the sign when dividing by a power of two
79
New cards
What is Rotate Right?
Form: ror Xd, Xn, Xm
Bit shifted out on the right are inserted on the left
32-bit form uses bits 0-31 only
80
New cards
What is Signed Extend Byte?
Form: sxtb Wd, Wn
- Sign extends bit 7 in Wn to bits 8-31
81
New cards
What is Signed Extend Halfword
* Form: sxth Wd, Wn
* Sign-extends bit 15 in Wn to bits 16-31
82
New cards
What is signed extend word?
o Form (64-bit only): sxtw Xd, Wn

o Sign-extends bit 31 to bits 32-63
83
New cards
What is Unsigned Extend Byte
Unsigned Extend Byteo Form (32-bit only): uxtb Wd, Wn

o Zero-extends bits 8-31
84
New cards
What is Unsigned Extend Halfword?
o Form (32-bit only): uxth Wd, Wn

o Zero-extends bits 16-31
85
New cards
What is Modulus Arithmetic
* Constrains number to the range 0 to M-1, where M is the modulus
* - CPUS normally do modulus arithmetic
86
New cards
Addition Binary Arithmetic
\
\
87
New cards
Subtraction Binary Arthmetic
Is done in the ALU by negating the subtrahend, and the adding

o Reuses the addition circuitry, thus minimizing hardware complexity

o 4-bit example: 7 -5 = 7 + (-5) = 2

0111

1011

\+====

1 0010

\
carry out is ignored
88
New cards
What is the basis of Multiplication of binary numbers
A conditional addition

An arithmetic shift right
89
New cards
What is the stack memory?
Is space in RAM provided by the OS to store data for functions
90
New cards
How much addresses can it store?
2^64 or 0xFFFFFFFFFFFFFFFF
91
New cards
What can be stored into RAM
Byte (1), halfword (2), word (4), doubleword (8)
92
New cards
What is the heap?
The heap is used for dynamically allocated memory in a program
93
New cards
What is the stack pointer?
The stack pointer register always points to the top of the stack
94
New cards
How much should the stack be alligned by
Quadword alligned
The address in SP must be evenly divisble by 16
95
New cards
What is the frame pointer?
* Is used to point to local variables in a stack frame
* A stack frame is pushed onto the stack when entering a function, must be at least 16 bytes long
96
New cards
What are stack variables
- Are created by allocating extra space in the stack frame when entering a function
97
New cards
How do you read and write stack variables
o Eg: Write 42 to the first stack variable

. . .

mov w20, 42

str w20, \[x29, 16\] -> x29 (base address), 16 (offset)

. . .

o Eg: Read from the second stack variable

. . .

ldr w21, \[x29, 20\] -> x29 (base address), 20 (offset)
98
New cards
Load Register Instruction
Load Register

o 64-bit for: ldr Xt, addr

Xt: register to be loaded

Addr: expression specifying the address in memory to read from

o Loads register with 8 bytes read from RAM

o Eg: ldr x22, \[x29, 56\]

o 32-bit from: ldr Wt, addr
99
New cards
Load Byte
Load Byte

o Form (32-bit only): ldrb Wt, addr

o Loads 1 byte from RAM into low-order part of Wt, zero-extending high-order bits
100
New cards
Load Signed Byte
Load Signed Byte

o Form (32-bit): ldrsb Wt, addr

o Form (64-bit): ldrsb Xt, addr

o Loads 1 byte from RAM into low-order part of Wt or Xt, signextendinghigh-order bits