4.2 ProcessorFundamentals.assembly_language Flashcards

1
Q

What is machine code?

A

Machine code is the programming language used by the CPU.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an instruction in the context of machine code?

A

An instruction is a single operation performed by the CPU.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is assembly language?

A

Assembly language is a low-level, chip-specific programming language that uses mnemonics.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define opcode.

A

Opcode, short for operation code, is the part of a machine code instruction that identifies the action the CPU will perform.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define operand.

A

Operand is the part of a machine code instruction that specifies the data to be used by the CPU.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is source code?

A

Source code is a computer program before it is translated into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an assembler?

A

An assembler is a program that translates assembly language into machine code. Assemblers can be one pass or two pass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an instruction set?

A

The instruction set is the complete set of machine code instructions used by a CPU.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is object code?

A

Object code is a computer program after it has been translated into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are addressing modes?

A

Addressing modes are methods of using the operand part of a machine code instruction as a memory address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is absolute addressing?

A

Absolute addressing is a mode where the contents of the memory location specified in the operand are used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is direct addressing?

A

Direct addressing is the same as absolute addressing, where the contents of the memory location specified in the operand are used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is indirect addressing?

A

Indirect addressing is a mode where the contents of the contents of the memory location specified in the operand are used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is indexed addressing?

A

Indexed addressing is a mode where the contents of the memory location found by adding the contents of the index register (IR) to the address specified in the operand are used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is immediate addressing?

A

Immediate addressing is a mode where only the value of the operand is used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is relative addressing?

A

Relative addressing is a mode where the memory address used is the current memory address added to the operand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is symbolic addressing?

A

Symbolic addressing is a mode used in assembly language programming where a label is used instead of a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the only programming language a CPU can use?

A

Machine code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Why does each computer or chip have its own machine code instructions?

A

Because machine code instructions are specific to the architecture of the computer or chip.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is stored in main memory for a CPU to carry out during the fetch-execute cycle?

A

A series of machine code instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does each machine code instruction perform?

A

Each instruction performs one simple task, such as storing a value in a memory location at a specified address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How is machine code typically displayed to make it easier for programmers to understand?

A

Machine code is often displayed as hexadecimal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the drawbacks of writing programs in machine code?

A

It is time-consuming, error-prone, and testing is only possible by running the program to see what happens.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Why were programming languages other than machine code developed?

A

To shorten development time and make instructions easier to learn and understand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is required for programs not written in machine code to be executed by the CPU?

A

They need to be translated into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What was the first programming language to be developed?

A

Assembly language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How is assembly language related to machine code?

A

It is closely related and uses mnemonics instead of binary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is an example of assembly language mnemonics?

A
  • LDD Total
  • ADD 20
  • STO Total
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the hexadecimal equivalent of the assembly mnemonics in the example?

A
  • LDD Total → 0140
  • ADD 20 → 0214
  • STO Total → 0340
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is the binary equivalent of the assembly mnemonics in the example?

A
  • LDD Total → 00000000110000000
  • ADD 20 → 00000001000011000
  • STO Total → 00000001110000000
31
Q

What is the structure of assembly language and machine code instructions?

A

Each instruction has:
- An opcode, identifying the operation to be carried out by the CPU.
- An operand, identifying the data to be used by the opcode.

32
Q

What must be done to a program written in assembly language before it can be executed?

A

It must be translated into machine code by an assembler.

33
Q

What is the role of an assembler?

A
  • Translates each assembly language instruction into a machine code instruction.
  • Checks the syntax of the assembly program to ensure only valid opcodes from the machine code instruction set are used.
34
Q

How does an assembler improve development time?

A

By identifying some errors during translation before the program is executed.

35
Q

What are the two types of assemblers?

A
  1. Single pass assembler: Translates and puts machine code instructions directly into memory for execution.
  2. Two pass assembler: Produces an object program in machine code that can be stored, loaded, and executed later. Requires an additional program called a loader.
36
Q

Why does a two pass assembler scan the source program twice?

A

To replace labels in the assembly program with memory addresses in the machine code program.

37
Q

In the assembly instruction LDD Total, what does “Total” represent?

38
Q

What happens during each pass of a two pass assembler?

A

Pass 1
- Reads the assembly program one line at a time.
- Ignores unnecessary elements (e.g., comments).
- Allocates memory addresses for each line of code.
- Checks if the opcode is in the instruction set.
- Adds new labels to the symbol table with their addresses (if known).
- Records the address of labelled instructions in the symbol table.
Pass 2
- Reads the assembly program line by line.
- Generates object code (including opcode and operand) using the symbol table created in Pass 1.
- Saves or executes the program.

39
Q

Why is a second pass necessary in a two pass assembler?

A

To resolve forward references, where labels are referred to before their addresses are known.

40
Q

Provide an example of a forward reference in assembly.

A
Notfound: LDD 200
          CMP #0
          JPN Found
          JPE Notfound
Found:    OUT

If the program is loaded at memory address 100 with 16-bit memory locations, the symbol table would be:

Label      Address  
Notfound   100  
Found      104 
41
Q

What does the instruction LDM #n do in assembly language?

A

It loads the number n directly into the accumulator (ACC) using immediate addressing.

42
Q

What does the instruction LDD <address> do?

A

It loads the contents of the specified address into the accumulator (ACC) using direct (or absolute) addressing.

43
Q

What is the purpose of the LDI <address> instruction?

A

It uses indirect addressing:

  • The address specified contains another address.
  • The contents of the address pointed to by this second address are loaded into the accumulator (ACC).
44
Q

What does the LDX <address> instruction accomplish?

A

It uses indexed addressing:

  • The address used is the specified address plus the contents of the Index Register (IX).
  • The contents of this calculated address are loaded into the accumulator (ACC).
45
Q

How is the LDR #n instruction different from LDM #n?

A
  • LDR #n loads the number n into the Index Register (IX) (immediate addressing).
  • LDM #n loads the number n into the Accumulator (ACC).
46
Q

What does the instruction LDR ACC do?

A

It loads the contents of the accumulator (ACC) into the Index Register (IX).

47
Q

What does the MOV <register> instruction do?</register>

A

It moves the contents of the accumulator (ACC) to the specified register (e.g., IX).

48
Q

Explain the purpose of the STO <address> instruction.

A

It stores the contents of the accumulator (ACC) into the specified memory address using direct (or absolute) addressing.

49
Q

What does the END instruction do in assembly language?

A

It returns control to the operating system, indicating the end of the program.

50
Q

What is the role of the IN instruction?

A

It allows the user to key in a character, storing its ASCII value in the accumulator (ACC).

51
Q

How does the OUT instruction work?

A

It outputs the character (corresponding to the ASCII value stored in the accumulator) to the screen.

52
Q

What are ACC and IX in assembly language?

A
  • ACC (Accumulator): A single register used for data storage, calculations, and comparisons.
  • IX (Index Register): A register used to calculate addresses in indexed addressing.
53
Q

What are the special prefixes for binary, hexadecimal, and denary numbers in assembly language?

A
  • Binary numbers: Prefix B (e.g., B01000011).
  • Hexadecimal numbers: Prefix & (e.g., &7B).
  • Denary numbers: Prefix # (e.g., #12).
54
Q

What does the JMP <address> instruction do?

A

It unconditionally jumps to the specified address, changing the program counter (PC) to the given address.

55
Q

How does the JPE <address> instruction work?

A

After a compare instruction, it jumps to the specified address if the comparison evaluates to True.

56
Q

What is the purpose of the JPN <address> instruction?

A

After a compare instruction, it jumps to the specified address if the comparison evaluates to False.

57
Q

How does a jump instruction affect program execution?

A

It changes the program counter (PC) to the specified address, making the next instruction to execute the one stored at that address instead of the next sequential memory location.

58
Q

What does the CMP <address> instruction do?

A

It compares the contents of the accumulator (ACC) with the contents of the specified address using direct addressing.

59
Q

How does the CMP #n instruction function?

A

It compares the contents of the accumulator (ACC) with the immediate number n.

60
Q

What is the role of the CMI <address> instruction?

A

It uses indirect addressing:

  • The address specified contains another address.
  • It compares the contents of the memory location pointed to by this second address with the contents of the accumulator (ACC).
61
Q

What is absolute addressing? Give an example.

A

The operand specifies the memory location directly.
Example:
If address 200 contains the value 20, the instruction LDD 200 will load 20 into the accumulator.

62
Q

How is direct addressing different from absolute addressing?

A

It is not different; direct addressing and absolute addressing are the same.

63
Q

What is indirect addressing? Give an example.

A

The operand specifies a memory location that contains another memory location.
Example:
If address 200 contains 20, and address 20 contains 5, the instruction LDI 200 will load 5 into the accumulator.

64
Q

Explain indexed addressing with an example.

A

The address is calculated by adding the value of the index register (IR) to the operand’s address.
Example:
If IR = 4 and address 204 contains 17, the instruction LDX 200 will load 17 into the accumulator.

65
Q

What is immediate addressing?

A

The operand is a literal value, not a memory address.
Example:
The instruction LDM #200 will load the value 200 directly into the accumulator.

66
Q

Describe relative addressing with an example.

A

The address is calculated by adding the operand to the current memory address.
Example:
The instruction JMR #5 transfers control to the instruction 5 locations after the current one.

67
Q

What is symbolic addressing, and where is it used?

A

Labels are used instead of numeric values for memory addresses, simplifying programming in assembly language.
Example:
If MyStore is a label for address 100 containing 20, the instruction LDD MyStore will load 20 into the accumulator.

68
Q

Why are labels used in assembly language?

A

Labels make it easier to modify programs by avoiding the need to update absolute addresses manually when inserting or changing instructions.

69
Q

What does a label do in assembly language?

A

A label provides a symbolic name for a memory location, making the code more readable and easier to maintain.

70
Q

How does assembly language compare to high-level languages in terms of instruction count?

A

Assembly language requires more instructions to perform the same task as a high-level language, which typically uses fewer, more abstract commands.

71
Q

Translate the high-level statement total = first + second + third into assembly language.

A
LDD first  
ADD second  
ADD third  
STO total  
END

example values:

first: #20
second: #30
third: #40
total: #0

LDD first: load the value stored at the memory location labeled first into the accumulator
STO total: store the contents of the accumulator into the memory location labeled total

If the program is loaded at memory address 100 and each memory location is 16 bits, the assigned memory addresses are:
- start: 100
- first: 106
- second: 107
- third: 108
- total: 109

A trace table would track the contents of the ACC (Accumulator), CIR (Current Instruction Register), and memory locations for first, second, third, and total as each instruction is executed.

72
Q

How does adding a list of numbers work in a high-level language?

A

FOR counter = 1 TO 3
total = total + number[counter]
NEXT counter

73
Q

How is a loop implemented in assembly language for adding a list of numbers?

A
  • Load 0 into ACC and store it in total and counter.
  • Set the index register (IX) to 0.
  • Use a loop to:
    • Load the number indexed by IX into ACC.
    • Add total to ACC and store the result back in total.
    • Increment IX and counter.
    • Compare counter with 3.
    • If counter is not equal to 3, jump back to loop.
  • End execution.
    LDM #0
    STO total
    STO counter
    LDR #0
loop: LDX number
    ADD total
    STO total 
    INC IX
    LDD counter
    INC ACC
    STO counter
    CMP #3 
    JPN loop
    END

number: #5
    #7
    #3
counter:
total:

If the program is to be loaded at memory address 100 after translation and each memory location contains 16 bits, the symbol table for this small section of program would look like this:

loop 104
number 115
counter 118
total 119

When this section of code is executed the contents of ACC, CIR, IX and the variables used can be traced using a trace table.