{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right 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 \z "FLOWWW.DOC-1006" \z "FLOWWW.DOC-1007" The assembler determines the smallest encoding possible for the direct unconditional jump. MASM does not require a distance operator, so you do not have to determine the correct distance of the jump. If you specify a distance, it overrides any assembler optimization. If the specified distance falls short of the
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern