LMAPGC07 - 161 CHAPTER 1 Very few programs execute all...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
161 CHAPTER 1 Very few programs execute all lines sequentially from .STARTUP to .EXIT . Rather, complex program logic and efficiency dictate that you control the flow of your program — jumping from one point to another, repeating an action until a condition is reached, and passing control to and from procedures. This chapter describes various ways for controlling program flow and several features that simplify coding program-control constructs. The first section covers jumps from one point in the program to another. It explains how MASM 6.1 optimizes both unconditional and conditional jumps under certain circumstances, so that you do not have to specify every attribute. The section also describes instructions you can use to test conditional jumps. The next section describes loop structures that repeat actions or evaluate conditions. It discusses MASM directives, such as .WHILE and .REPEAT , that generate appropriate compare, loop, and jump instructions for you, and the .IF , .ELSE , and .ELSEIF directives that generate jump instructions. The “Procedures” section in this chapter explains how to write an assembly- language procedure. It covers the extended functionality for PROC , a PROTO directive that lets you write procedure prototypes similar to those used in C, an INVOKE directive that automates parameter passing, and options for the stack- frame setup inside procedures. The last section explains how to pass program control to an interrupt routine. Jumps \z "FLOWWW.DOC-1001" \z "FLOWWW.DOC-1002" Jumps are the most direct way to change program control from one location to another. At the processor level, jumps work by changing the value of the IP (Instruction Pointer) register to a target offset and, for far jumps, by changing the CS register to a new segment address. Jump instructions fall into only two categories: conditional and unconditional. Unconditional Jumps \z "FLOWWW.DOC-1003" \z "FLOWWW.DOC-1004" \z "FLOWWW.DOC-1005" The JMP instruction transfers control unconditionally to another instruction. JMP ’s single operand contains the address of the target instruction. Filename: d16315dce724866944cffac25a61aa5da0c393dd.DOC Project: Template: Author: Last Saved By: Revision #: 0 Page: 161 of 52 Printed: 11/04/92 11:29 A11/P11
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programmer’s Guide Unconditional jumps skip over code that should not be executed, as shown here: ; Handle one case label1: . . . jmp continue ; Handle second case label2: . . . jmp continue . . . continue: The distance of the target from the jump instruction and the size of the operand determine the assembler’s encoding of the instruction. The longer the distance, the more bytes the assembler uses to code the instruction. In versions of MASM prior to 6.0, unconditional NEAR jumps sometimes generated inefficient code, but MASM can now optimize unconditional jumps. Jump Optimizing
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/24/2012 for the course EE 3751 taught by Professor Desouza during the Spring '04 term at LSU.

Page1 / 52

LMAPGC07 - 161 CHAPTER 1 Very few programs execute all...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online