MASM, ALU, Common Syntax , Variables, Data Segments Flashcards

1
Q

(True or false) END main is a directive that tells the operating system where to begin execution of the program

A

True

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

(True/False): A MASM program must have a procedure named “main”.

A

False
The ‘main’ procedure can have any valid identifier, as long as the END directive properly points the assembler to start execution at that identifier address.

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

This directive is used to mark the beginning of the code segment in memory.

A

.code

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

(True/False): Assembly language directives execute at runtime.

A

False
Directives are used by the assembler prior to runtime.

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

(True/False): Assembly language directives can be written in any combination of uppercase and lowercase letters.

A

True

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

Which of the following identifiers are invalid, and why?
count0
1newval
Spacer*
sym4?
loop

A

valid
invalid - Identifiers cannot start with a number
invalid - Asterisks may not be part of identifiers.
valid
invalid - “loop” is a reserved word, instruction

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

(True/False): An identifier cannot begin with a numeric digit.

A

True

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

(True/False): B2h is a valid hexadecimal integer literal.

A

False
Integer literals with non-numeric characters as the first character must be preceded by a 0. Correct format would be 0B2h.

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

(True/False): 4b is a valid binary integer literal .

A

False
4 is not a valid binary digit.

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

(True/False): A hexadecimal literal may be written as 0x3A in MASM.

A

False
Proper notation would be 3Ah or 03Ah

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

(True/False): String literals must be enclosed in double-quotes.

A

False
String literals may be enclosed either in single- or double-quotes.

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

What are the main components of instruction statements?

A

Code Label (optional)
Instruction Mnemonic (required)
Operands (often required)
Comment (Optional)

[code_label:] mnemonic [operands] [;comment]

For example …

_SumTwoValues: ADD EAX, EBX ;Sum eax/ebx, store result in

Note there is one instruction which does nothing. NOP (no operation) is assembled, but has no function other than to take up space and is sometimes used to align code to specific address boundaries.

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

What are the two types of MASM labels, and what are their functions

A

Code Lables - provide named instruction addresses and are defined and used in the code segment. They refer to the specific memory locations in the code segment. They allow us to use the label name rather than the address offset when needed.

Data labels - provide named variable addresses and are defined in the data segment;

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

What is the instruction mnemonic?

A

The code-phrase we use to indicate which instruction we are executing. Often it will be descriptive of the underlying function. We may refer to them simply as ‘instructions’.

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

What are basic uses of operands?

A

Instructions may have zero, one, or more operands. Some instructions can even be used with a varying number of operands. For instructions which allow multiple operands, MASM syntax usually puts the destination operand, or the operand specifying where the result will go, as the first operand. ADD EAX, EBX would therefore sum the contents of EAX and EBX and store the result in EAX. This ordering is counter-intuitive and causes numerous headaches, but is part of Intel syntax guidelines! Please note there are exceptions where there is a single operand and it is not a destination operand.

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

How can you define comments in MASM?

A

Single line comments are indicated with a semicolon (;). They often follow a line of code as you’ve already seen on this page, but may be used on their own line as well.

Multi-line (block) comments are specified with the COMMENT directive and a special character (delimiter) which the software engineer defines. All lines following the special character are ignored until the assembler encounters the special character again. For example, using the exclamation point (!) as the special character:

COMMENT !
Name: Grace Hopper
Date: September 9, 1947
Issue: Mark II Aiken Relay Malfunctioning
Resolved: 15:45 Relay #70 Panel F (moth) in relay. First actual case of bug being found.

17
Q

Name the four basic parts of an assembly language instruction.

A

Code label, instruction mnemonic, operand(s), comment

18
Q

How are data labels and code labels different?

A

Data labels exist in the data segment as variable offsets. Code labels are in the code segment, and are offsets for transfer of control instructions.

19
Q

(True/False): A code label is followed by a colon (:), but a data label does not end with a colon.

20
Q

(True/False): MOV is an example of an instruction mnemonic.

21
Q

(True/False): All instructions have operands.

A

False
Some have none (e.g. STD) while others have one or more (e.g. MUL)

22
Q

Convert the following instructions with operands to the same instruction but with operand types. For example, given ADD EDX, varA you would write ADD reg32, mem32.

Instructions with operands Instruction with operand types
INC AL
MOV varA, AX
MUL EBX
ADD DH, 14

A

Instructions with operands Instruction with operand types
INC AL INC reg8 or INC accum8
MOV varA, AX MOV mem16, reg16 or MOV mem16, accum16
MUL EBX MUL reg32
ADD DH, 14 ADD reg8, imm or ADD reg8, imm8

23
Q

Convert the following instructions with operand types to the same instruction but with valid operands of the same type. For example, given MOV reg8, imm, one acceptable answer would be MOV AL, ‘q’.
Instructions with operand types Instruction with operands
MOV reg16, reg16
DIV reg32
ADD accum32, imm
MOV mem32, reg32

A

Instructions with operand types Instruction with operands
MOV reg16, reg16 MOV AX, DX
DIV reg32 DIV EBX
ADD accum32, imm ADD EAX, 4
MOV mem32, reg32 MOV count, ECX or MOV 0A04h, ECX
Note that direct entry of memory addresses such as 0A04h is valid syntax.

24
Q

What are the instruction types that we will use in this class?

A

Instruction Type Purpose Example
Data Movement- Copy data from one location to another. - MOV, MOVSX, LODSB, XCHG, PUSH
Arithmetic/Logic - Perform arithmetic or logical operations - ADD, IMUL, XOR
Comparison - Compare multiple values to set flags - CMP, TEST
Branching - Transfer program execution to another point in the program space - JMP, JNE, JS
Procedure - Control execution of procedures within program - CALL, RET, ENTER, LEAVE
Control Instructions - Modify the system flags, change how instructions function - CLD, CLI

25
Q

(True/False) An immediate may be a destination operand.

A

False*
Destination operands must be capable of receiving data. Immediates are literal values and cannot represent registers or memory locations as instruction operands. *Note one exception, the OUT instruction, may have an 8-bit immediate specify an output port.

26
Q

What instruction will subtract the value in the source operand from that of the destination operand, and save the result in the destination operand?

27
Q

(True/False) The ADD instruction must have an explicit destination operand.

28
Q

(True/False) The MUL instruction must have an explicit destination operand.

A

False
MUL has an implied destination operand (EDX:EAX for 32-bit inputs, DX:AX for 16-bit inputs, and AX for 8-bit inputs).

29
Q

(True/False) The MUL instruction is used to multiply signed integers.

A

False
IMUL must be used for signed integer multiplication.