Introduction to Assembly Language and Computer Architecture

Chapter 1: Introduction

Q&A

Questions

  1. How do assemblers and linkers work together?
  2. How will studying assembly language enhance your understanding of operating systems?
  3. What is meant by a one-to-many relationship when comparing a high-level language to machine language?
  4. Explain the concept of portability as it applies to programming languages.
  5. Is the assembly language for x86 processors the same as those for computer systems such as the Vax or Motorola 68×00?
  6. Give an example of an embedded systems application.
  7. What is a device driver?
  8. Do you suppose type checking on pointer variables is stronger (stricter) in assembly language or in C and C++?
  9. Name two types of applications that would be better suited to assembly language than a high-level language.
  10. Why would a high-level language not be an ideal tool for writing a program that directly accesses a particular brand of printer?
  11. Why is assembly language not usually used when writing large application programs?
  12. Challenge: Translate the following C++ expression to assembly language, using the example presented earlier in this chapter as a guide: X = (Y * 4) + 3.

Answers

  1. An assembler converts source-code programs from assembly language into machine language. A linker combines individual files created by an assembler into a single executable program.
  2. 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.
  3. In a one-to-many relationship, a single statement expands into multiple assembly language or machine instructions.
  4. A language whose source programs can be compiled and run on a wide variety of computer systems is said to be portable.
  5. No. Each assembly language is based on either a processor family or a specific computer.
  6. Some examples of embedded systems applications are automobile fuel and ignition systems, air-conditioning control systems, security systems, flight control systems, hand-held computers, modems, printers, and other intelligent computer peripherals.
  7. Device drivers are programs that translate general operating system commands into specific references to hardware details that only the manufacturer knows.
  8. C++ does not allow a pointer of one type to be assigned to a pointer of another type. Assembly language has no such restriction regarding pointers.
  9. Applications suited to assembly language: hardware device driver and embedded systems and computer games requiring direct hardware access.
  10. 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.
  11. 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.

Q&A

Questions

  1. In your own words, describe the virtual machine concept.
  2. Why don’t programmers write application programs in machine language?
  3. (True/False): When an interpreted program written in language L1 runs, each of its instructions is decoded and executed by a program written in language L0.
  4. Explain the technique of translation when dealing with languages at different virtual machine levels.
  5. At which level does assembly language appear in the virtual machine example shown in this section?
  6. What software permits compiled Java programs to run on almost any computer?
  7. Name the four virtual machine levels named in this section, from lowest to highest.
  8. Why don’t programmers write applications in machine language?
  9. Machine language is used at which level of the virtual machine shown in Figure 1-1?
  10. Statements at the assembly language level of a virtual machine are translated into statements at which other level?

Answers

  1. 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.
  2. Machine language: It is enormously detailed and consists purely of numbers. Hard for humans to understand.
  3. True.
  4. 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.
  5. Assembly language appears at Level 3.
  6. The Java virtual machine (JVM) allows compiled Java programs to run on almost any computer.
  7. Digital logic, instruction set architecture, assembly language, high-level language.
  8. Machine language is difficult for humans to understand since it provides no visual clues relating to the instruction syntax.
  9. Instruction set architecture.
  10. Level 2 (Instruction Set Architecture).

Q&A

Questions

  1. The central processor unit (CPU) contains registers and what other basic elements?
  2. The central processor unit is connected to the rest of the computer system using what three buses?
  3. Why does memory access take more machine cycles than register access?
  4. What are the three basic steps in the instruction execution cycle?
  5. Which two additional steps are required in the instruction execution cycle when a memory operand is used?
  6. During which stage of the instruction execution cycle is the program counter incremented?
  7. When a program runs, what information does the OS read from the filename’s disk directory entry?
  8. After a program has been loaded into memory, how does it begin execution?
  9. Define multitasking.
  10. What is the function of the OS scheduler?
  11. When the processor switches from one task to another, what values in the first task’s state must be preserved?
  12. What is the duration of a single clock cycle in a 3-GHz processor?

Answers

  1. Control Unit, Arithmetic Logic Unit, and the clock.
  2. Data, Address, and Control buses.
  3. Conventional memory is outside the CPU, and it responds more slowly to access requests. Registers are hard-wired inside the CPU.
  4. Fetch, decode, execute.
  5. Fetch memory operands, store memory operands.
  6. During the fetch step.
  7. 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.)
  8. The OS executes a branch (like a GOTO) to the first machine instruction in the program.
  9. 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.
  10. The OS scheduler determines how much time to allot to each task, and it switches between tasks.
  11. The program counter, the task’s variables, and the CPU registers (including the status flags).
  12. 3.33 x 10-10, which is 1.0/3.0 x 10-9.

Q&A

Questions

  1. What are the x86 processor’s three basic modes of operation?
  2. Name all eight 32-bit general-purpose registers.
  3. Name all six segment registers.
  4. What special purpose does the ECX register serve?
  5. Besides the stack pointer (ESP), what other register points to variables on the stack?
  6. Name at least four CPU status flags.
  7. Which flag is set when the result of an unsigned arithmetic operation is too large to fit into the destination?
  8. Which flag is set when the result of a signed arithmetic operation is either too large or too small to fit into the destination?
  9. Which flag is set when an arithmetic or logical operation generates a negative result?
  10. Which part of the CPU performs floating-point arithmetic?
  11. How many bits long are the FPU data registers?
  12. Which Intel processor was the first member of the IA-32 family?
  13. Which Intel processor first introduced superscalar execution?
  14. Which Intel processor first used MMX technology?
  15. Describe the CISC design approach.
  16. Describe the RISC design approach.

Answers

  1. Real-address mode, Protected mode, and System Management mode.
  2. EAX, EBX, ECX, EDX, ESI, EDI, ESP, EBP.
  3. CS, DS, SS, ES, FS, GS.
  4. Loop counter.
  5. EBP.
  6. Most common: Carry, Sign, Zero, Overflow. Less common: Auxiliary Carry, Parity.
  7. Carry.
  8. Overflow.
  9. Sign.
  10. Floating-Point Unit.
  11. 80 bits.
  12. The Intel 80386.
  13. The Pentium.
  14. The Pentium II.
  15. CISC means complex instruction set: a large collection of instructions, some of which perform sophisticated operations that might be typical of a high-level language.
  16. The term RISC stands for reduced instruction set: a small set of simple (atomic) instructions that may be combined into more complex operations.

Q&A

Questions

  1. What is the range of addressable memory in protected mode?
  2. What is the range of addressable memory in real-address mode?
  3. The two ways of describing an address in real-address mode are segment-offset and ______________.
  4. In real-address mode, convert the following hexadecimal segment-offset address to a linear address: 0950:0100.
  5. In real-address mode, convert the following hexadecimal segment-offset address to a linear address: 0CD1:02E0.
  6. In MASM’s flat segmentation model, how many bits hold the address of an instruction or variable?
  7. In protected mode, which register references the descriptor for the stack segment?
  8. In protected mode, which table contains pointers to memory segments used by a single program?
  9. In the flat segmentation model, which table contains pointers to at least two segments?
  10. What is the main advantage to using the paging feature of x86 processors?
  11. Challenge: Can you think of a reason why MS-DOS was not designed to support protected-mode programming?
  12. Challenge: In real-address mode, demonstrate two segment-offset addresses that point to the same linear address.

Answers

  1. 4 GByte (0 to FFFFFFFFh).
  2. 1 MByte (0 to FFFFFh).
  3. Linear (absolute).
  4. 09600h.
  5. 0CFF0h.
  6. 32 bits.
  7. SS register.
  8. Local descriptor table.
  9. Global descriptor table.
  10. The total size of all programs loaded into memory can exceed the amount of physical memory installed in the computer.
  11. 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.
  12. The following segment-offset addresses point to the same linear address: 0640:0100 and 0630:0200.

Q&A

Questions

  1. Describe SRAM and its most common use.
  2. Describe VRAM.
  3. List at least two features found in the Intel P965 Express chipset.
  4. Name four types of RAM mentioned in this chapter.
  5. Which type of RAM is used for Level 2 cache memory?
  6. What advantages does a USB device offer over a standard serial or parallel device?
  7. What is the purpose of the 8259A PIC controller?
  8. What are the main differences between Wi-Fi and Bluetooth?

Answers

  1. SRAM is an acronym for Static RAM, used in CPU cache memory.
  2. VRAM (video ram) holds displayable video data. When CRT monitors are used, VRAM is dual ported, allowing one port to continuously refresh the display while another port writes data to the display.
    • Intel Fast Memory Access uses an updated Memory Controller Hub (MCH).
    • I/O Controller Hub (Intel ICH8/R/DH) that supports serial ATA devices (disk drives).
    • Support for 10 USB ports, 6 PCI express slots, networking, and Intel Quiet System technology.
    • High definition audio chip.
  3. Dynamic RAM, Static RAM, Video RAM, and CMOS RAM.
  4. Static RAM.
  5. The computer can query a device connected via USB to find out its name and device type and the type of driver it supports. The computer can also suspend power to individual devices. None of these capabilities is possible with serial and parallel ports.
  6. The 8259 is the interrupt controller chip, sometimes called PIC, that schedules hardware interrupts and interrupts the CPU.
  7. Bluetooth is a wireless communication protocol for exchanging small amounts of data over short distances. It is commonly used with mobile devices such as cell phones and PDAs. Wi-Fi devices operate at a greater speed and capacity than Bluetooth. Wi-Fi devices often communicate with each other when in the range of a wireless network.

Q&A

Questions

  1. Of the four levels of input/output in a computer system, which is the most universal and portable?
  2. What characteristics distinguish BIOS-level input/output?
  3. Why are device drivers necessary, given that the BIOS already has code that communicates with the computer’s hardware?
  4. In the example regarding displaying a string of characters, which level exists between the operating system and the video controller card?
  5. At which level(s) can an assembly language program manipulate input/output?
  6. Why do game programs often send their sound output directly to the sound card’s hardware ports?
  7. Challenge: Is it likely that the BIOS for a computer running MS-Windows would be different from that used by a computer running Linux?

Answers

  1. The application program level.
  2. BIOS functions communicate directly with the system hardware. They are independent of the operating system.
  3. New devices are invented all the time with capabilities that were often not anticipated when the BIOS was written.
  4. The BIOS level.
  5. The operating system, BIOS, and hardware levels.
  6. Game programs often try to take advantage of the latest features in specialized sound cards. It should be noted that MS-DOS game applications were more prone to do this than games running under MS-Windows. In fact, Windows-NT, 2000, and XP all prevent applications from directly accessing system hardware.
  7. No. The same BIOS would work for both operating systems. Many computer owners install two or three operating systems on the same computer. They would certainly not want to change the system BIOS every time they rebooted the computer!