Assembly Language Lab # 9

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

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

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

The x86 Architecture

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

Computer Architecture and Assembly Language. Practical Session 3

Chapter 3: Addressing Modes

Experiment 8 8 Subroutine Handling Instructions and Macros

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

EEM336 Microprocessors I. Data Movement Instructions

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

Procedures and the Stack. Chapter 4 S. Dandamudi

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

EEM336 Microprocessors I. Addressing Modes

Stack, subprograms. procedures and modular programming role of stack while using procedures stack implementation (Pentium)

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures. Chapter Overview. The Book's Link Library

Libraries and Procedures

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Assembly Language for Intel-Based Computers, 4 th Edition

Addressing Modes on the x86

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

Experiment 3 3 Basic Input Output

Introduction to IA-32. Jo, Heeseung

Module 3 Instruction Set Architecture (ISA)

INTRODUCTION TO IA-32. Jo, Heeseung

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

Libraries and Procedures

x86 Assembly Tutorial COS 318: Fall 2017

Assembler Programming. Lecture 2

Basic Execution Environment

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

Chapter 11. Addressing Modes

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

Hardware and Software Architecture. Chapter 2

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

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

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Complex Instruction Set Computer (CISC)

CS241 Computer Organization Spring 2015 IA

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

Assembly Language Programming: Procedures. EECE416 uc. Charles Kim Howard University. Fall

COE 205. Computer Organization and Assembly Language Dr. Aiman El-Maleh

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

CS401 Assembly Language Solved MCQS From Midterm Papers

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

SYSC3601 Microprocessor Systems. Unit 2: The Intel 8086 Architecture and Programming Model

Reverse Engineering II: The Basics

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Lab 2: Introduction to Assembly Language Programming

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

Computer Architecture and System Software Lecture 06: Assembly Language Programming

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

The Microprocessor and its Architecture

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 5: Procedures

COMPUTER ENGINEERING DEPARTMENT

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

Ethical Hacking. Assembly Language Tutorial

ADDRESSING MODES. Operands specify the data to be used by an instruction

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

16.317: Microprocessor Systems Design I Fall 2014

16.317: Microprocessor Systems Design I Fall 2015

System calls and assembler

Assembly Language. Lecture 5 Procedures

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

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

Assembly Language. Lecture 5 Procedures

Computer Architecture and System Software Lecture 07: Assembly Language Programming

Assembly Language Lab # 12 Part A: Strings and Arrays Part B: Drawing Graphics Using INT 10h

Practical Malware Analysis

We will first study the basic instructions for doing multiplications and divisions

PHY4635/5635 Spring Lecture 8: Program Control Instructions

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

LAB 5 Arithmetic Operations Simple Calculator

16.317: Microprocessor Systems Design I Spring 2015

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

The x86 Architecture. ICS312 - Spring 2018 Machine-Level and Systems Programming. Henri Casanova

Credits and Disclaimers

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-11: 80x86 Architecture

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Chapter 2: The Microprocessor and its Architecture

The Instruction Set. Chapter 5

Addressing Modes. Outline

EC-333 Microprocessor and Interfacing Techniques

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

Assembly Language: Function Calls

Project 1: Bootloader. COS 318 Fall 2015

Program Exploitation Intro

Lab 3. The Art of Assembly Language (II)

16.317: Microprocessor Systems Design I Fall 2013

Advanced Microprocessors

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

if 2 16bit operands multiplied the result will be

Instruction Set Architectures

Assembly Language: Function Calls" Goals of this Lecture"

GLOBAL EDITION. Assembly Language. for x86 Processors SEVENTH EDITION. Kip R. Irvine

Transcription:

Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2011 Assembly Language Lab # 9 Stacks and Subroutines Eng. Doaa Abu Jabal

Assembly Language Lab # 9 Stacks and Subroutines Objective: To learned how to use the stack and write assembly procedures. Stacks: The stack is part of memory used for temporary storage of addresses and data. It's LIFO structure, The stack sorts data in 2 bytes. The SS and SP registers point to the top of the stack like this: SS:[SP]. So the SS register is the segment and the SP register contains the offset. The PUSH instruction is used to place values on the stack and the POP instruction is used to remove values from the stack. When we dealing with stack in the program we write:.stack To determine the size of the stack, which we want to use it, we put it as follows:.stack 100h 1. PUSH Instruction The PUSH instruction first decrements ESP and then copies either a 16- or 32-bit source operand into the stack. A 16-bit operand causes ESP to be decremented by 2. A 32-bit operand causes ESP to be decremented by 4. There are three instruction formats: PUSH r /m16 PUSH r /m32 PUSH imm32 2

3 2. POP Instruction The POP instruction first copies the contents of the stack element pointed to by ESP into a 16- or 32-bit destination operand and then increments ESP. If the operand is 16 bits, ESP is incremented by 2; if the operand is 32 bits, ESP is incremented by 4. There are two instruction formats: POP r /m16 POP r /m32 3. PUSHFD and POPFD Instructions The PUSHFD instruction pushes the 32-bit EFLAGS register on the stack, and POPFD pops the stack into EFLAGS: pushfd popfd 4. PUSHAD, PUSHA, POPAD, and POPA The PUSHAD instruction pushes all of the 32- bit general-purpose registers on the stack in the following order: EAX, ECX, EDX, EBX, ESP, EBP, ESI, and EDI. The POPAD instruction pops the same registers off the stack in reverse order. The PUSHA instruction, pushes the l6-bit general-purpose registers (AX, CX, DX, BX, SP, BP, SI, DI) on the stack in the order listed. The POPA instruction pops the same registers in reverse order. Note: we will use the following interrupt services: Service 01h: DOS get character function mov ah,01h ; returns ASCII code of character to AL int 21h ; and echo it to the monitor Service 02h: DOS print character function mov ah,02h mov dl,ascii# ; ASCII code of character for print in DL int 21h Service 08h: Get character without echo mov ah,08h ; returns ASCII code of character to AL int 21h ; but don t echo it to the monitor

Lab work: Example 1: Write an assembly language program asks the user to enter a password formed from 8 characters. The program prints the password as stars on the screen. If the password is right, the program should print 'Correct Password'. Else, It will print 'Incorrect Password' 4

Subroutines: a subroutine is a special part of the program that can be called for execution from any point in the program. The subroutine is written to provide a function that must be performed frequently at various points in the main program. Whenever the function must be performed, a single instruction is inserted into the main body of the program to CALL the subroutine. RET instruction must be included at the end of the subroutine to return to the main program. The CALL instruction: calls a procedure pushes offset of next instruction on the stack copies the address of the called procedure into EIP The RET instruction: returns from a procedure pops top of stack into EIP Suggested documentation for each procedure: A description of all tasks accomplished by the procedure. Receives: A list of input parameters; state their usage and requirements. Returns: A description of values returned by the procedure. Requires: Optional list of requirements called preconditions that must be satisfied before the procedure is called. Note: To convert a hexadecimal digit (x) to its ASCII code (y): x+30h if 0<x<9 y = x+37h if A<x<F ERROR else 5

Lab work: Example 2: This program calls a subroutine that finds the largest number in a vector with N elements: 6

Homework: H.W 1: Write an assembly program that gets a character from Keyboard and displays its ASCII. H.W 2: Write a procedure that sets the Zero flag if the 32-bit integer passed in the EAX register is prime. (A prime number is evenly divisible by only itself and 1 ) Optimize the program's loop to run as efficiently as possible. Your program should prompt the user for a number and then display a message indicating whether or not the number is prime. The program should then ask for another number from the user. Continue the loop in this fashion until the user enters a prearranged value such as -1. 7