PHY4635/5635 Spring Lecture 8: Program Control Instructions

Similar documents
Program Control Instructions

6/29/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

The Stack. Lecture 15: The Stack. The Stack. Adding Elements. What is it? What is it used for?

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

Objectives. ICT106 Fundamentals of Computer Systems Topic 8. Procedures, Calling and Exit conventions, Run-time Stack Ref: Irvine, Ch 5 & 8

Intel 8086: Instruction Set

SHEET-2 ANSWERS. [1] Rewrite Program 2-3 to transfer one word at a time instead of one byte.

UNIT 4. Modular Programming

PESIT Bangalore South Campus

EC-333 Microprocessor and Interfacing Techniques

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Lecture (08) x86 programming 7

A4 Sample Solution Ch3

EEM336 Microprocessors I. Addressing Modes

Assembly Language Lab # 9

Experiment 8 8 Subroutine Handling Instructions and Macros

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

2003 LXI H, 42F2H ; this instruction store 42F2 in to the HL pair POP H ; store data from top of the stack to HL pair

Chapter 3. Assembly Language Programming with 8086

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

Parameter Passing. Procedure line. Calling procedure line. Most subroutines require parameters Can sometimes pass parameters via registers

Topics Introduction to Microprocessors. Chapter 5 Macros and modules. What is macro? How to use macro? (I) How to use macro?

LABORATORY WORK NO. 8 WORKING WITH MACROS AND LIBRARIES

Assembler Programming. Lecture 10

CS401 Assembly Language Solved MCQS From Midterm Papers

Lecture 16: Passing Parameters on the Stack. Push Examples. Pop Examples. CALL and RET

Chapter 3: Addressing Modes

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

ORG ; TWO. Assembly Language Programming

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler:

Procedures and the Stack. Chapter 4 S. Dandamudi

if 2 16bit operands multiplied the result will be

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

db "Please enter up to 256 characters (press Enter Key to finish): ",0dh,0ah,'$'

Midterm Exam #2 Answer Key

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

Computer Architecture and System Software Lecture 06: Assembly Language Programming

Week /8086 Microprocessor Programming II

EC 333 Microprocessor and Interfacing Techniques (3+1)

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Computer Architecture and System Software Lecture 07: Assembly Language Programming

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

x86 Assembly Tutorial COS 318: Fall 2017

Summer 2003 Lecture 14 07/02/03

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

Module 3 Instruction Set Architecture (ISA)

Assignment no:4 on chapter no :3 : Instruction set of 8086

Week /8086 Microprocessor Programming


SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

The x86 Architecture

Q. State and Explain steps involved in program development. [w-08, w-10, s-12, w-11]

8086 programming Control Flow Instructions and Program Structures

UMBC. 1 (Feb. 9, 2002) seg_base + base + index. Systems Design & Programming 80x86 Assembly II CMPE 310. Base-Plus-Index addressing:

Q1: Multiple choice / 20 Q2: Protected mode memory accesses

3.1 DATA MOVEMENT INSTRUCTIONS 45

Summer 2003 Lecture 4 06/14/03

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

Computer Systems Lecture 9

Dr. D.M. Akbar Hussain

UNIVERSITY OF CALIFORNIA, RIVERSIDE

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU

ELEC 242 Time Delay Procedure

16.317: Microprocessor Systems Design I Fall 2014

EEM336 Microprocessors I. Data Movement Instructions

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

CS-202 Microprocessor and Assembly Language

Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top

8086 ALP TOOLS (CH 2) CHAPTER 2

Assembler lecture 5 S.Šimoňák, DCI FEEI TU of Košice

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

Code segment Stack segment

Chapter Four Instructions Set

Summer 2003 Lecture 15 07/03/03

Intel x86 Memory. Architecture. The x86 isn't all that complex it just doesn't make a lot of sense. Program Segments. x86 Data and Address Ranges

16.317: Microprocessor Systems Design I Spring 2015

Come and join us at WebLyceum

8086 INSTRUCTION SET

1: /********************************************************** 2: * A

Intel Instruction Set (gas)

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Computer Architecture and Assembly Language. Practical Session 3

EC 333 Microprocessor and Interfacing Techniques (3+1)

Architecture and components of Computer System Execution of program instructions

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

CSC 8400: Computer Systems. Machine-Level Representation of Programs

CS401 Assembly Language Solved Subjective MAY 03,2012 From Midterm Papers. MC

COMPUTER ENGINEERING DEPARTMENT

BAHAR DÖNEMİ MİKROİŞLEMCİLER LAB3 FÖYÜ

COE 205 Lab Manual Experiment N o 12. Experiment N o Using the Mouse

16.317: Microprocessor Systems Design I Fall 2013

Experiment 3 3 Basic Input Output

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

Transcription:

PHY4635/5635 Spring 2009 Lecture 8: Program Control Instructions

Short, Near and Far Jumps Short jump: jump is within +127 to -128 bytes from the address following the jump. Relative jumps : moves with the code since it stores only the relative distance within the instruction (relocatable). JMP $+2 ; jumps over the next two memory locations JMP SHORT LABEL ; the SHORT is not necessary. Near jump: jump is within ±32K bytes (anywhere in the current code segment) from the address following the jump (segments are cyclic). Note, the range is ±2GB for the 80386+ Also Relative (relocatable) Uses a sign-extended 16-bit displacement (808x) or 32-bit (80386+) JMP NEAR PTR LABEL ; the NEAR is not necessary Far jump: jump to anywhere in the real mode (intersegment jump) Obtains a new segment and offset (not relative). JMP FAR PRT LABEL You need not code a particular type of jump the assembler will do it for you.

Short, Near and Far Jumps Far jump to an external: EXTRN UP:FAR ; Defines a FAR label ( ) START: XOR BX,BX MOV AX,1 ADD AX,BX JMP NEAR PTR NEXT ; NEAR PTR not necessary ( ) NEXT: MOV BX,AX JMP START JMP FAR PTR UP ( ) Inside the routine that contains UP label ( ) MOV AX,FFh UP:: MOV BX,1 ; Note the use of :: to indicate that it may be ; accessed by other routines as an EXTRN. ( ) Linker inserts the address of the UP label into the JMP UP instruction for you. It also inserts the segment address of the JMP START instruction

Indirect Jumps Register holds the jump address Allows you to select where to jump based on a table of labels.

Indirect Jumps Register holds the jump address Allows you to select where to jump based on a table of labels.

SET Either set a byte (01h) or clear a byte (00h) after checking a condition. Nice to store the state of the machine into memory at one point in the code for use later. SETNC MEMLOC ;Sets MEMLOC to 1 if C-bit=0

LOOP LOOP: Combines DEC CX with JNZ. LOOP LABEL ;LABEL is near Similar to REP with string instructions which decrements CX and stops loop when CX=0. LOOPD (ECX) and LOOPW (CX) in 80386+ Other forms (combines C and Z-flags): LOOPE (Loop while equal) (same as LOOPZ): Loops if a condition is equal (Z=1) AND CX 0 LOOPNE (Loop while not equal) (same as LOOPNZ): Loops if a condition is not equal (Z=0) AND CX 0.

The STACK Temporary holding space for WORD data Usually do not need to reference specific stack memory, but FYI SS:SP Points to top of stack play with SP to index down into the stack. Be careful all data is 1 word in length! All segments, including stack, rolls over at boundaries PUSH places a word of data on top of the stack (never a byte) POP pulls a word of data memory off the top of the stack (never a byte) LIFO (Last In, First Out)

PUSH AX The Stack

POP BX The Stack

PUSHA (not recognized in WinASM) The Stack

Procedures (subroutines) CALL pushes the IP onto the stack (location of next sequential instruction) for use when returning (RET) from procedure. RET - Used within a procedure, pops the IP back for continued program flow CLRSCRN PROC NEAR ;PROC directive labels it as a proc ( ) RET CLRSCRN ENDP

Procedures (subroutines) Near CALL (intrasegment) are used locally PUSHes IP 3-bytes long (OP and ±32K distance added to the IP), same as near jump. Far CALL (intersegment) are used globally PUSHes CS AND IP 5-bytes long (must contain complete address can point to any memory location) Near or Far determined in PROC statement during assembly and link.

CALLs with register operands ( ) ( ) DISP DISP ( ) ;Write OK to screen MOV BX, OFFSET DISP MOV DL, O CALL BX ;BX holds DISP offset. MOV DL, K CALL BX PROC NEAR MOV AH,2 INT 21h RET ENDP

CALLs with indirect memory address Useful when different subroutines need to be chosen based on conditions

Example from skeleton.asm ;==============subroutine CLS=============== ;clear video screen by getting and setting video mode ;uses BIOS INT 10H ;inputs -- none ;outputs -- none ;destroys -- nuthin' ;----------------------------------------------------------------- cls proc near pushall ;uses pushall macro sub bh,bh mov ah,0fh int 10h sub ah,ah int 10h popall ;uses popall macro Ret cls EndP

Example from skeleton.asm ;==============subroutine CLS=============== ;clear video screen by getting and setting video mode ;uses BIOS INT 10H ;inputs -- none ;outputs -- none ;destroys -- nuthin' ;----------------------------------------------------------------- cls proc near call pushall ;uses pushall procedure sub bh,bh mov ah,0fh int 10h sub ah,ah int 10h call popall ;uses popall procedure Ret cls EndP

PUSHALL/POPALL PROCEDURES ;====subroutine PUSHALL===== ;push all registers to stack ;uses nuthin ;inputs -- none ;outputs -- none ;destroys -- nuthin' ;-------------------------------------------- pushall proc near push ax push bx push cx push dx Ret cls EndP ;====subroutine POPALL===== ;push all registers to stack ;uses nuthin ;inputs -- none ;outputs -- none ;destroys -- nuthin' ;-------------------------------------------- pushall proc near pop dx pop cx pop bx pop ax Ret cls EndP