Beruflich Dokumente
Kultur Dokumente
Assembly language is not portable because it is designed for a specific processor family.
How will studying assembly language enhance your understanding of operating systems?
Assembly language is a good tool for learning how application programs communicate
with the computer’s operating system via interrupt handlers, system calls, and common
memory areas. Assembly language programming also helps when learning how the operating
system loads and executes application programs.
Name two types of applications that would be better suited to assembly language than a
high-level language.?
Applications suited to assembly language: hardware device driver and embedded systems
and computer games requiring direct hardware access.
Why would a high-level language not be an ideal tool for writing a program that directly
accesses a particular brand of printer?
A high-level language may not provide for direct hardware access. Even if it does, awkward
coding techniques must often be used, resulting in possible maintenance problems.
Why is assembly language not usually used when writing large application programs?
Assembly language has minimal formal structure, so structure must be imposed by programmers
who have varying levels of experience. This leads to difficulties maintaining existing
code.
Challenge: Translate the following C++ expression to assembly language, using the
example presented earlier in this chapter as a guide: X (Y * 4) 3.
Code for the expression X
_
(Y * 4)
_
3:
mov eax,Y ; move Y to EAX
mov ebx,4 ; move 4 to EBX
imul ebx ; EAX = EAX * EBX
add eax,3 ; add 3 to EAX
mov X,eax ; move EAX to X
In your own words, describe the virtual machine concept.?
Virtual machine concept: Computers are constructed in layers, so that each layer represents
a translation layer from a higher-level instruction set to a lower-level instruction set.
Explain the technique of translation when dealing with languages at different virtual
machine levels?
An entire L1 program is converted into an L0 program by an L0 program specifically
designed for this purpose. Then the resulting L0 program is executed directly on the computer
hardware.
At which level does assembly language appear in the virtual machine example shown in
this
section?
Assembly language appears at Level 3.
What software permits compiled Java programs to run on almost any computer?
The Java virtual machine (JVM) allows compiled Java programs to run on almost any
computer.
Name the four virtual machine levels named in this section, from lowest to highest.?
Digital logic, instruction set architecture, assembly language, high-level language.
Machine language is used at which level of the virtual machine shown in Figure 1–1?
Instruction set architecture.
Statements at the assembly language level of a virtual machine are translated into
statements at which other level?
Level 2 (Instruction Set Architecture).
The central processor unit (CPU) contains registers and what other basic elements?
Control Unit, Arithmetic Logic Unit, and the clock.
The central processor unit is connected to the rest of the computer system using what three
buses?
Data, Address, and Control buses.
Why does memory access take more machine cycles than register access?
Conventional memory is outside the CPU and it responds more slowly to access requests.
Registers are hard-wired inside the CPU.
What are the three basic steps in the instruction execution cycle?
Fetch, decode, execute.
Which two additional steps are required in the instruction execution cycle when a memory
operand is used?
Fetch memory operands, store memory operands.
During which stage of the instruction execution cycle is the program counter incremented?
During the fetch step.
When a program runs, what information does the OS read from the filename’s disk
directory entry?
Section 2.1.4 mentions the filename, file size, and starting location on the disk. (Most
directories also store the file’s last modification date and time.)
After a program has been loaded into memory, how does it begin execution?
The OS executes a branch (like a GOTO) to the first machine instruction in the program
Define multitasking.?
The CPU executes multiple tasks (programs) by rapidly switching from one program to the
next. This gives the impression that all programs are executing at the same time.
When the processor switches from one task to another, what values in the first task’s state
must be preserved?
The program counter, the task’s variables, and the CPU registers (including the status flags.
Besides the stack pointer (ESP), what other register points to variables on the stack?
EBP
Which flag is set when the result of an unsigned arithmetic operation is too large to fit into
the destination?
Carry.
Which flag is set when the result of a signed arithmetic operation is either too large or too
small to fit into the destination?
Overflow.
Which flag is set when an arithmetic or logical operation generates a negative result?
Sign.
Which Intel processor was the first member of the IA-32 family?
The Intel 80386.
The two ways of describing an address in real-address mode are segment-offset and
______________.?
Linear (absolute).
In MASM’s flat segmentation model, how many bits hold the address of an instruction or
variable?
32 bits.
In protected mode, which register references the descriptor for the stack segment?
SS register.
In protected mode, which table contains pointers to memory segments used by a single
program?
Local descriptor table.
In the flat segmentation model, which table contains pointers to at least two segments?
Global descriptor table.
What is the main advantage to using the paging feature of x86 processors?
The total size of all programs loaded into memory can exceed the amount of physical
memory installed in the computer.
Challenge: Can you think of a reason why MS-DOS was not designed to support protected
mode programming?
This is an open-ended question, of course. It is a fact that MS-DOS first had to run on the
8086/8088 processors, which only supported Real-address mode. When later processors
came out that supported Protected mode, my guess is that Microsoft wanted MS-DOS to
continue to run on the older processors. Otherwise, customers with older computers would
refuse to upgrade to new versions of MS-DOS.
(Yes/No): Does the multiplication operator (*) have a higher precedence than the division
operator (/) in integer expressions?
No (they have the same precedence).
Write a constant expression that divides 10 by 3 and returns the integer remainder.?
Expression: 10 MOD 3.
Why would it not be a good idea to use numeric addresses when writing instructions that
access variables?
Because the addresses coded in the instructions would have to be updated whenever new
variables were inserted before existing ones.
In the AddSub program (Section 3.2), what is the meaning of the INCLUDE directive?
The INCLUDE directive copies necessary definitions and setup information from the Irvine32.inc
text file. The data from this file is inserted into the data stream read by the
assembler.
(True/False): The linker extracts assembled procedures from the link library and inserts
them in the executable program?
True.
(True/False): When a program’s source code is modified, it must be assembled and linked
again before it can be executed with the changes.?
True.
Declare a 32-bit signed integer variable and initialize it with the smallest possible negative
decimal value. (Hint: Refer to integer ranges in Chapter 1.)?
var5 SDWORD-2147483648
Declare an unsigned 16-bit integer variable named wArray that uses three initializers?
wArray WORD 10, 20, 30
Declare a string variable containing the name of your favorite color. Initialize it as a
nullterminated string?
myColor BYTE “blue”, 0
Declare a string variable containing the word “TEST” repeated 500 times?
myTestString BYTE 500 DUP(“TEST”)
Declare an array of 20 unsigned bytes named bArray and initialize all elements to zero.?
myTestString BYTE 500 DUP(“TEST”)
Show the order of individual bytes in memory (lowest to highest) for the following doubleword variable:
val1 DWORD 87654321h?
(True/False): The EIP register cannot be the destination operand of a MOV instruction?
True
Use the following variable definitions for the remaining questions in this section:
.data
var1 SBYTE -4,-2,3,1
var2 WORD 1000h,2000h,3000h,4000h
var3 SWORD -16,-42
var4 DWORD 1,2,3,4,5
For each of the following statements, state whether or not the instruction is valid:
a. mov ax,var1 Ans:not valid
b. mov ax,var2 Ans:valid
c. mov eax,var3 Ans:not valid
d. mov var2,var3 Ans:not valid
e. movzx ax,var2 Ans:not valid
f. movzx var2,al Ans:not valid
g. mov ds,ax Ans:valid
h. mov ds,1000h Ans:not valid
What will be the hexadecimal value of the destination operand after each of the following
instructions execute in sequence?
mov al,var1 ; a. a= FCh
mov ah,[var1+3] ; b. b= 01h
What will be the value of the destination operand after each of the following instructions
execute in sequence?
mov ax,var2 ; a. a= 1000h
mov ax,[var2+4] ; b. b= 3000h
If val2 is incremented by 1 using the ADD instruction, what will be the values of the Carry
and Sign flags?
CF=0, SF=1.
If val4 is incremented by 1 using the ADD instruction, what will be the values of the Overflow and Sign flags?
OF=1, SF=1.
Where indicated, write down the values of the Carry, Sign, Zero, and Overflow flags after
each instruction has executed:
mov ax,7FF0h
add al,10h ; a. CF = 1 SF = 0 ZF = 1 OF =0
add ah,1 ; b. CF =0 SF =1 ZF =0 OF =1
add ax,2 ; c. CF =0 SF =1 ZF =0 OF =0
(Yes/No): Is it possible to set the Overflow flag if you add a positive integer to a negative
integer?
No.
(Yes/No): Will the Overflow flag be set if you add a negative integer to a negative integer
and produce a positive result?
Yes.
(Yes/No): Is it possible for the NEG instruction to set the Overflow flag?
Yes (for example, mov al, 128 . . . followed by . . . neg al).
(Yes/No): Is it possible for both the Sign and Zero flags to be set at the same time?
No.
Write a sequence of two instructions that set both the Carry and Overflow flags at the same
time?
Setting the Carry and Overflow flags at the same time:
mov al,80h
add al,80h
Write a sequence of instructions showing how the Zero flag could be used to indicate
unsigned overflow after executing INC and DEC instructions?
Setting the Zero flag after INC and DEC to indicate unsigned overflow:
mov al,0FFh
inc al
jz overflow_occurred
mov bl,1
dec bl
jz overflow_occurred
In our discussion of the Carry flag we subtracted unsigned 2 from 1 by negating the 2 and
adding it to 1. The Carry flag was the inversion of the carry out of the MSB of the sum.
Demonstrate this process by subtracting 3 from 4 and show how the Carry flag value is
produced.
Subtracting 3 from 4 (unsigned). Carry out of MSB is inverted and placed in the Carry flag:
111111
0 0 0 0 1 0 0 (4)
_ 1 1 1 1 1 1 0 1 (_3)
0 0 0 0 0 0 0 1 (1)
mov al,4
sub al,3 ; CF = 0