Exam 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The registers listed in the USES directive must use commas to separate the register names

false

A link library consists of assembly language object code.

true

dll file extension stands for Dynamic Link Library

true

Write a loop that iterates through a double-word array and calculates the sum of its elements using a scale factor with indexed addressing

.data intarray DWORD 10000h,20000h,30000h,40000h .code main proc mov edi, OFFSET intarray mov ecx, LENGTHOF intarray mov eax, 0 L1: add eax, [edi] add edi, TYPE intarray loop L1 invoke ExitProcess, 0 main endp end main

TYPEDEF

The TYPEDEF operator lets you create a user-defined type that has all the status of a built-in type when defining variables. TYPEDEF is ideal for creating pointer variables. For example, the following declaration creates a new data type PBYTE that is a pointer to bytes: PBYTE TYPEDEF PTR BYTE

Use the Irvine32 library for all standard I/O and data conversion WaitMsg

The WaitMsg procedure displays the message "Press any key to continue. . ." and waits for the user to press a key.

CMP - compares operands using implied subtraction sets condition flags

CMP Results ZF CF Destination < source 0 1 Destination > source 0 0 Destination = source 1 0 CMP Results Flags Destination < source SF ≠ OF Destination > source SF = OF Destination = source ZF = 1

Local variables in procedures are created on the stack

true

NEG

The NEG (negate) instruction reverses the sign of a number by converting the number to its two's complement. The Carry, Zero, Sign, Overflow, Auxiliary Carry, and Parity flags are changed according to the value that is placed in the destination operand.

indexed

An indexed operand adds a constant to a register to generate an effective address. Any of the 32-bit general-purpose registers may be used as index registers. There are different notational forms permitted by MASM (the brackets are part of the notation): constant[reg] [constant + reg] The first notational form combines the name of a variable with a register. The variable name is translated by the assembler into a constant that represents the variable's offset. Here are examples that show both notational forms: arrayB[esi] [arrayB + esi] arrayD[ebx] [arrayD + ebx] Indexed operands are ideally suited to array processing. The index register should be initialized to zero before accessing the first array element: .data arrayB BYTE 10h,20h,30h .code mov esi,0 mov al,arrayB[esi] ; AL = 10h

indirect

An indirect operand can be any 32-bit general-purpose register (EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP) surrounded by brackets. The register is assumed to contain the address of some data. In the next example, ESI contains the offset of byteVal. The MOV instruction uses the indirect operand as the source, the offset in ESI is dereferenced, and a byte is moved to AL: .data byteVal BYTE 10h .code mov esi,OFFSET byteVal mov al,[esi] ; AL = 10h If the destination operand uses indirect addressing, a new value is placed in memory at the location pointed to by the register. In the following example, the contents of the BL register are copied to the memory location addressed by ESI. mov [esi],bl

Which of the following registers are needed for input parameters when call ReadString procedure? EDX EBX ESP ECX

EDX ECX

In order to use Irvine32.inc library, which of the following is required? INCLUDING Irvine32.inc USE Irvine32.inc INCLUDE Irvine32.inc USING Irvine32.inc

INCLUDE Irvine32.inc

Carry flag

Indicates carrying out or borrowing into the leftmost bit position following an arithmetic operation; also modified by some of the shift and rotate operations.

Conditional Jumps & Loops flag values: JC

JC Jump if carry CF = 1

Conditional Jumps & Loops flag values: JNC

JNC Jump if not carry CF = 0

Conditional Jumps & Loops flag values: JP

JP Jump if parity (even) PF = 1

Conditional Jumps & Loops flag values: JZ

JZ Jump if zero ZF = 1

Conditional Jumps & Loops equality: JE

Jump if equal (leftOp = rightOp)

Conditional Jumps & Loops equality: JNE

Jump if not equal (leftOp ≠ rightOp)

Runtime stack

LIFO structure The runtime stack is a memory array managed directly by the CPU, using the ESP (extended stack pointer) register, known as the stack pointer register. ESP always points to the last value to be added to, or pushed on, the top of stack.

Conditional Jumps & Loops signed: JG

Signed Comparison Jump if greater (if leftOp > rightOp)

Conditional Jumps & Loops signed: JL

Signed Comparison Jump if less (if leftOp < rightOp)

Conditional Jumps & Loops signed: JNG

Signed Comparison Jump if less than or equal (if leftOp ≤ rightOp) Jump if not greater (same as JLE)

Procedure - named block of executable code

Suppose that in main, a CALL statement is located at offset 00000020. Typically, this instruction requires 5 bytes of machine code, so the next statement (a MOV in this case) is located at offset 00000025: main PROC 00000020 call MySub 00000025 mov eax,ebx Next, suppose that the first executable instruction in MySub is located at offset 00000040: MySub PROC 00000040 mov eax,edx . . ret MySub ENDP

ADD

The ADD instruction adds a source operand to a destination operand of the same size. The Carry, Zero, Sign, Overflow, Auxiliary Carry, and Parity flags are changed according to the value that is placed in the destination operand.

Bitwise instructions AND manipulate individual bits in operands

The AND instruction performs a boolean (bitwise) AND operation between each pair of matching bits in two operands and places the result in the destination operand: x y x ∧ y 0 0 0 0 1 0 1 0 0 1 1 1

Procedure

The CALL instruction calls a procedure by directing the processor to begin execution at a new memory location. The procedure uses a RET (return from procedure) instruction to bring the processor back to the point in the program where the procedure was called.

Use the Irvine32 library for all standard I/O and data conversion Clrscr

The Clrscr procedure clears the console window.

Use the Irvine32 library for all standard I/O and data conversion Crlf

The Crlf procedure advances the cursor to the beginning of the next line in the console window.

JMP

The JMP instruction causes an unconditional transfer to a destination, identified by a code label that is translated by the assembler into an offset.

LENGTHOF

The LENGTHOF operator returns the number of elements in an array.

LOOP

The LOOP instruction, formally known as Loop According to ECX Counter, repeats a block of statements a specific number of times. ECX is automatically used as a counter and is decremented each time the loop repeats.

Conditional Jumps & Loops LOOPE

The LOOPE (loop if equal) instruction is equivalent to LOOPZ, and they share the same opcode. They perform the following tasks:

Conditional Jumps & Loops LOOPNE

The LOOPNZ (loop if not zero) instruction is the counterpart of LOOPZ. The loop continues while the unsigned value of ECX is greater than zero (after being decremented) and the Zero flag is clear. The syntax is LOOPNZ destination

Conditional Jumps & Loops LOOPNZ

The LOOPNZ (loop if not zero) instruction is the counterpart of LOOPZ. The loop continues while the unsigned value of ECX is greater than zero (after being decremented) and the Zero flag is clear. The syntax is LOOPNZ destination

Conditional Jumps & Loops LOOPZ

The LOOPZ (loop if zero) instruction works just like the LOOP instruction except that it has one additional condition: the Zero flag must be set in order for control to transfer to the destination label. The syntax is LOOPZ destination

MOV - data transfer from source to destination

The MOV instruction copies data from a source operand to a destination operand. Known as a data transfer instruction, it is used in virtually every program. Its basic format shows that the first operand is the destination and the second operand is the source: MOV destination,source

MOVSX

The MOVSX instruction (move with sign-extend) copies the contents of a source operand into a destination operand and sign-extends the value to 16 or 32 bits. This instruction is only used with signed integers. There are three variants: MOVSX reg32,reg/mem8 MOVSX reg32,reg/mem16 MOVSX reg16,reg/mem8

MOVZX

The MOVZX instruction (move with zero-extend) copies the contents of a source operand into a destination operand and zero-extends the value to 16 or 32 bits. This instruction is only used with unsigned integers. There are three variants: MOVZX reg32,reg/mem8 MOVZX reg32,reg/mem16 MOVZX reg16,reg/mem8 .data byteVal BYTE 10001111b .code movzx ax,byteVal ; AX = 0000000010001111b mov bx,0A69Bh movzx eax,bx ; EAX = 0000A69Bh movzx edx,bl ; EDX = 0000009Bh movzx cx,bl ; CX = 009Bh

Bitwise instructions NOT manipulate individual bits in operands

The NOT instruction toggles (inverts) all bits in an operand. The result is called the one's complement. mov al,11110000b not al ; AL = 00001111b

OFFSET

The OFFSET operator returns the offset of a data label. The offset represents the distance, in bytes, of the label from the beginning of the data segment. .data bVal BYTE ? wVal WORD ? dVal DWORD ? dVal2 DWORD ? If bVal were located at offset 00404000 (hexadecimal), the OFFSET operator would return the following values: mov esi,OFFSET bVal ; ESI = 00404000h mov esi,OFFSET wVal ; ESI = 00404001h mov esi,OFFSET dVal ; ESI = 00404003h mov esi,OFFSET dVal2 ; ESI = 00404007h

Bitwise instructions OR manipulate individual bits in operands

The OR instruction performs a boolean OR operation between each pair of matching bits in two operands and places the result in the destination operand: x y x ∨ y: 0 0 0 0 1 1 1 0 1 1 1 1

Overflow flags

The Overflow flag indicates signed integer overflow. For example, if an instruction has a 16-bit destination operand but it generates a negative result smaller than decimal, the Overflow flag is set.

PTR

The PTR operator lets you override an operand's default size. Suppose, for example, that you would like to move the lower 16 bits of a doubleword variable named myDouble into AX. The assembler will not permit the following move because the operand sizes do not match: .data myDouble DWORD 12345678h .code mov ax,myDouble ; error But the WORD PTR operator makes it possible to move the low-order word (5678h) to AX: mov ax,WORD PTR myDouble

Use the Irvine32 library for all standard I/O and data conversion RandomRange

The RandomRange procedure produces a random integer within the range of 0 to where n is an input parameter passed in the EAX register.

SIZEOF

The SIZEOF operator returns the number of bytes used by an array initializer. The SIZEOF operator returns a value that is equivalent to multiplying LENGTHOF by TYPE.

SUB

The SUB instruction subtracts a source operand from a destination operand. The set of possible operands is the same as for the ADD and MOV instructions. The Carry, Zero, Sign, Overflow, Auxiliary Carry, and Parity flags are changed according to the value that is placed in the destination operand.

Use the Irvine32 library for all standard I/O and data conversion SetTextColor

The SetTextColor procedure (Irvine32 library only) sets the foreground and background colors for text output. When calling SetTextColor, assign a color attribute to EAX.

Sign flag

The Sign flag indicates that an operation produced a negative result. If the most significant bit (MSB) of the destination operand is set, the Sign flag is set.

Bitwise instructions TEST manipulate individual bits in operands

The TEST instruction performs an implied AND operation between each pair of matching bits in two operands and sets the Sign, Zero, and Parity flags based on the value assigned to the destination operand. The only difference between TEST and AND is that TEST does not modify the destination operand. 0 0 1 0 0 1 0 1 <- input value 0 0 0 0 1 0 0 1 <- test value 0 0 0 0 0 0 0 1 <- result: ZF = 0 0 0 1 0 0 1 0 0 <- input value 0 0 0 0 1 0 0 1 <- test value 0 0 0 0 0 0 0 0 <- result: ZF = 1

TYPE

The TYPE operator returns the size, in bytes, of a single element of a variable. For example, the TYPE of a byte equals 1, the TYPE of a word equals 2, the TYPE of a doubleword is 4, and the TYPE of a quadword is 8.

XCHG

The XCHG (exchange data) instruction exchanges the contents of two operands. There are three variants: XCHG reg,reg XCHG reg,mem XCHG mem,reg

Bitwise instructions XOR manipulate individual bits in operands

The XOR instruction performs a boolean exclusive-OR operation between each pair of matching bits in two operands and stores the result in the destination operand: x y x ⊕ y 0 0 0 0 1 1 1 0 1 1 1 0 x y x ⊕ y (x ⊕ y) ⊕ y 0 0 0 0 0 1 1 0 1 0 1 1 1 1 0 1

Zero flag

The Zero flag indicates that an operation produced zero. For example, if an operand is subtracted from another of equal value, the Zero flag is set.

Conditional Jumps & Loops unsigned: JA

Unsigned comparison Jump if above (if leftOp > rightOp)

Conditional Jumps & Loops unsigned: JB

Unsigned comparison Jump if below (if leftOp < rightOp)

Conditional Jumps & Loops unsigned: JNA

Unsigned comparison Jump if below or equal (if leftOp ≤ rightOp) Jump if not above (same as JBE)

direct memory operands

Variable names are references to offsets within the data segment. For example, the following declaration for a variable named var1 says that its size attribute is byte and it contains the value 10 hexadecimal: .data var1 BYTE 10h

Which of the following procedure from the linked library is used to write an unsigned integer to the console window in decimal form? Write WriteDec RandomRange WaitMsg

WriteDec

direct-offset operands

You can add a displacement to the name of a variable, creating a direct-offset operand. This lets you access memory locations that may not have explicit labels. Let's begin with an array of bytes named arrayB: arrayB BYTE 10h,20h,30h,40h,50h ; Direct-Offset Addressing (byte array): mov al,arrayB ; AL = 10h mov al,[arrayB+1] ; AL = 20h mov al,[arrayB+2] ; AL = 30h arrayW WORD 100h,200h,300h ; Direct-Offset Addressing (word array): mov ax,arrayW ; AX = 100h mov ax,[arrayW+2] ; AX = 200h arrayD DWORD 10000h,20000h ; Direct-Offset Addressing (doubleword array): mov eax,arrayD ; EAX = 10000h mov eax,[arrayD+4] ; EAX = 20000h mov eax,[arrayD+4] ;EAX = 20000h

INC

add 1 from a register or memory operand. The Overflow, Sign, Zero, Auxiliary Carry, and Parity flags are changed according to the value of the destination operand. The INC and DEC instructions do not affect the Carry flag (which is something of a surprise).

Runtime stack - LIFO structure PUSH:

add value to stack The PUSH instruction first decrements ESP and then copies a source operand into the stack.

Write a single instruction that converts an ASCII digit in AL to its corresponding binary value. If AL already contains a binary value (00h to 09h), leave it unchanged

and al, 00001111b

Use the Irvine32 library for all standard I/O and data conversion Basic input/out functions, such as Write(/Read)Int(/Hex/Dec/Char/String)

call ReadInt ; reads integer from keyboard and puts value in EAX call ReadHex ; reads hexadecimal from keyboard and puts value in EAX call ReadDec ; reads unsigned integer from keyboard and puts value in EAX call ReadChar ; reads character from keyboard and puts value in AL call ReadString ; reads string from keyboard and puts value in EDX call WriteInt ; writes integer value in EAX call WriteHex ; writes hexadecimal value in EAX call WriteDec ; writes unsigned integer value in EAX call WriteChar ; writes character value in AL call WriteString ; writes string value in EDX

Write instructions that jump to label L1 when the unsigned integer in DX is less than or equal to the integer in CX

cmp dx, cx JBE L1 L1:

Write instructions that jump to label L1 when the signed integer in DX is less than or equal to the integer in CX

cmp dx, cx JLE L1 L1:

If the RET instruction is omitted from a procedure, the code will not be assembled

false

In 32-bit mode, the register ESI register manages the stack.

false

Nested procedure calls are not permitted by the Microsoft assebler unless the NESTED operator is used in the procedure definition

false

The ESI and EDI registers cannot be used when passing 32-bit parameters to procedures

false

The USES operator only generates push instructions, so you must code pop instruction yourself

false

Write a Call statement that calls a procedure name MyProc in an external link library: MyProc Call

false

Write a sequence of two instructions that use addition to set the Zero and Carry flags at the same time

mov al, 0FFh add al, 1

Write a sequence of two instructions that set both the Carry and Overflow flags at the same time

mov al, 3 sub al, 4

Write an instruction that moves the second byte in myWords to the AL register Use the following data definition .data myBytes BYTE 10h, 20h, 30h, 40h myWords WORD 3 DUP(?), 200h

mov al, BYTE PTR myWords + 1

Write a sequence of instruction showing how the Zero flag could be used to indicate unsinged overflow after executing INC and DEC instructions

mov al,0FFh inc al jz INC_overflow mov bl,1 dec bl jz DEC_overflow INC_overflow: DEC_overflow:

Write a sequence of MOV instruction that will exchange the upper and lower words in a double-word variable named three

mov ax, word ptr three mov bx, word ptr three+2 mov three, bx mov word ptr three+2, ax

Write an instruction that moves all four bytes in myByte to the EAX register Use the following data definition .data myBytes BYTE 10h, 20h, 30h, 40h myWords WORD 3 DUP(?), 200h

mov eax, DWORD PTR myBytes

Write a sequence of statements that display a subroutine's return address. Be sure that whatever modifications you make to the stack do not prevent the subroutine from returning to its caller

mov eax, [esp] call WriteHex

Write a sequence of statements using indexed addressing that copies an element in a double word array to the previous position in the same array

mov edi, esi dec edi mov edx, array[esi*4] mov array[edi*4], edx

Insert a LABEL directive in the given data that permits myBytes to be moved directly to a 16-bit register Use the following data definition .data myBytes BYTE 10h, 20h, 30h, 40h myWords WORD 3 DUP(?), 200h

myWordsD LABEL DWORD myWords WORD 3 DUP(?), 2000h .code mov eax, myWordsD

Which instruction pop the stack into the EFLAGS registers? popf popa popfd popef

popfd

Write a sequence of statements that use only PUSH and POP instructions to exchange the values in the EAX and EBX registers

push ebx push eax pop ebx pop eax

Runtime stack - LIFO structure POP:

remove value from stack The POP instruction first copies the contents of the stack element pointed to by ESP into a 16- or 32-bit destination operand and then increments ESP. If the operand is 16 bits, ESP is incremented by 2; if the operand is 32 bits, ESP is incremented by 4:

Runtime stack - LIFO structure holds:

return addresses, parameters, local variables

Suppose there is no push instruction. You write your own two lines of code to equivalent push EAX to stack. Which of the following is correct? sub [esp], 4 mov esp, eax sub esp, 4 mov [esp], eax sub [esp], 2 mov esp, eax sub esp, 2 mov [esp], eax

sub esp, 4 mov [esp], eax

DEC

subtract 1 from a register or memory operand. The Overflow, Sign, Zero, Auxiliary Carry, and Parity flags are changed according to the value of the destination operand. The INC and DEC instructions do not affect the Carry flag (which is something of a surprise).

CMP - compares operands using implied subtraction

the CMP instruction to compare integers. Character codes are also integers, so they work with CMP as well. Floating-point values require specialized comparison instructions

If I have USES ESI ECX in procedure head, it is equivalent to have PUSH ESI PUSH ECX at the beginning of the procedure and POP ECX POP ESI at the end of the procedure (Before RET instruction)

true

In protected mode, each procedure call uses a minimum of 4 bytes of stack space

true

It is not possible to define a procedure inside an existing procedure

true

Stack is called a LIFO data structure

true

The Call instruction pushes the offset of the instruction following the Call on the stack

true

The PROC directive begins a procedure and the ENDP directive ends a procedure

true

The RET instruction pops the tip of the stack into the instruction pointer

true

The USES operator lets you name all register that are modified within a procedure

true

The running time stack holds the return address of called procedures

true

Use the PROTO directive to declare a procedure named MyProc in an external link library: MyProc PROTO

true

Using the XCHG instruction no more than three times, reorder the values in four 8-bit registers from the order A, B, C, D to B, C, D, A

xchg A, B xchg A, C xchg A, D


Kaugnay na mga set ng pag-aaral

Chapter 2 The Concept of Object Orientation

View Set

Introduction to Psychology Final

View Set

Chapter 8 - concepts - PED, YED, XED

View Set