Jump instructions. Unconditional jumps. Direct jump. do not change flags. Jump



Similar documents
Complete 8086 instruction set

x64 Cheat Sheet Fall 2015

Faculty of Engineering Student Number:

Computer Organization and Assembly Language

How To Use A Computer With A Screen On It (For A Powerbook)

Character Translation Methods

A Tiny Guide to Programming in 32-bit x86 Assembly Language

8. MACROS, Modules, and Mouse

Overview of IA-32 assembly programming. Lars Ailo Bongo University of Tromsø

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

PART B QUESTIONS AND ANSWERS UNIT I

INTRODUCTION TO PROGRAMMING THE 8086

8085 INSTRUCTION SET

CS61: Systems Programing and Machine Organization

MACHINE ARCHITECTURE & LANGUAGE

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

Computer Organization and Architecture

Instruction Set Architecture

Machine-Level Programming II: Arithmetic & Control

Assembly Language Tutorial

King Fahd University of Petroleum and Minerals. College of Computer Science and Engineering. Computer Engineering Department COE 205

Z80 Instruction Set. Z80 Assembly Language

Notes on Assembly Language

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Instruction Set Architecture (ISA)

CPU Organization and Assembly Language

Unpacked BCD Arithmetic. BCD (ASCII) Arithmetic. Where and Why is BCD used? From the SQL Server Manual. Packed BCD, ASCII, Unpacked BCD

Instruction Set Architecture

Embedded x86 Programming: Protected Mode

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

The x86 PC: Assembly Language, Design, and Interfacing 5 th Edition

by Kip Irvine. Last update: 12/11/2003

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

Gazi Üniversitesi Bilgisayar Mühendislii Bölümü

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

MACHINE INSTRUCTIONS AND PROGRAMS

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

LC-3 Assembly Language

Instruction Set. Microcontroller Instruction Set. Instructions that Affect Flag Settings (1) The Instruction Set and Addressing Modes

EECS 427 RISC PROCESSOR

Administration. Instruction scheduling. Modern processors. Examples. Simplified architecture model. CS 412 Introduction to Compilers

Abysssec Research. 1) Advisory information. 2) Vulnerable version

Instruction Set Design

The 80x86 Instruction Set

PROBLEMS (Cap. 4 - Istruzioni macchina)

Where we are CS 4120 Introduction to Compilers Abstract Assembly Instruction selection mov e1 , e2 jmp e cmp e1 , e2 [jne je jgt ] l push e1 call e

IA-32 Intel Architecture Software Developer s Manual

64-Bit NASM Notes. Invoking 64-Bit NASM

MICROPROCESSOR AND MICROCOMPUTER BASICS

Chapter 9 Computer Design Basics!

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

Machine Programming II: Instruc8ons

LABORATORY MANUAL EE0310 MICROPROCESSOR & MICROCONTROLLER LAB

Using Debug 1 INTRODUCING DEBUG

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

1 Classical Universal Computer 3

Microprocessor/Microcontroller. Introduction

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

Embedded X86 Programming: Protected Mode

Writing an 8086 emulator in Python

CHAPTER 6 TASK MANAGEMENT

X86-64 Architecture Guide

Systems Design & Programming Data Movement Instructions. Intel Assembly

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

HC12 Assembly Language Programming

Intel 8086 architecture

Chapter 7 Assembly Language

Test Driven Development in Assembler a little story about growing software from nothing

Attacks on Virtual Machine Emulators

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Where s the FEEB? The Effectiveness of Instruction Set Randomization

1 The Java Virtual Machine

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Chapter 5, The Instruction Set Architecture Level

Analysis of Win32.Scream

PC Assembly Language. Paul A. Carter

Writing a Simple Operating System from Scratch

THUMB Instruction Set

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University

Software Fingerprinting for Automated Malicious Code Analysis

Flash Microcontroller. Architectural Overview. Features. Block Diagram. Figure 1. Block Diagram of the AT89C core

Systems I: Computer Organization and Architecture

Chapter 2 Assemblers

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

CPU performance monitoring using the Time-Stamp Counter register

CHAPTER 7: The CPU and Memory

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

CS 16: Assembly Language Programming for the IBM PC and Compatibles

REpsych. : psycholigical warfare in reverse engineering. def con 2015 // domas

Outline. Lecture 3. Basics. Logical vs. physical memory physical memory. x86 byte ordering

8051 Serial Port. Crystal TXD. I/O Device RXD. Embedded Systems Peripherals

Bypassing Anti- Virus Scanners

Self Protection Techniques in Malware

Transcription:

do not change flags. Unconditional jumps Jump Jump instructions near the target label is in the same segment than the jump far jump to another code segment Direct jump jmp label Near jump jmp Stop xor ax,ax Stop: mov ah,4ch Machine code: cs:0000 EB 03 cs:0002 90 cs:0003 33 00 cs:0005 B4 4C displacement = the difference between the target label and IP (may also be negative) jmp Stop nop xor ax,ax Stop: mov ah,4ch Assembly Languag 6/ 1

A processor executes the jump adding the displacement to the current value of IP (IP := 0002 + 3 = 0005) => IP will point to the instruction at which the program execution shall continue. Two-pass assembler scans the source assembly language program twice. The purpose of the 1st pass is to work out the locations corresponding to symbols (identifiers). To work out these locations, the assembler uses a variable known as the location counter (LC). The symbol table is created during the first pass; it records the names of variables and labels together with their attributes. LC =.DATA 0 Number DW 1234h 2 Array DW 100 dup(?) 202 Value DB 5,6,7 205 Symbol table: Symbol Segment Offset Type Number _Data 0 variable: word Array _Data 2 variable: word Value _Data 202 variable: byte Assembly Languag 6/ 2

.CODE LC = 0 Start: mov ax,@data 3 mov ds,ax 5 mov cx,number 9 Next: dec cx 10 Symbol table: Symbol Segment Offset Type Start _Text 0 label: near Next _Text 9 label: near Problem: forward jumps A 16-bit displacement -32768; 32767 is supposed, i.e. the assembler reserves two bytes for the displacement of a forward jump instruction. In the 2nd pass the assembler uses the symbol table to generate the machine code. If the displacement is an 8-bit value 127, the second byte is filled with the op-code for instruction nop. Operator short instructs the assembler to use an 8-bit displacement: cs:0000 EB 02 cs:0002 33 00 cs:0004 B4 4C jmp short Stop xor ax,ax Stop: mov ah,4ch Assembly Languag 6/ 3

Far jump The machine code operand of far jump is the complete address of the destination in the order: offset, segment (4 bytes). A processor executes the jump loading IP by the offset and CS by the segment. If the forward jump is a far jump, we must instruct the assembler to reserve 4 bytes for the operand by defining the far type label: jmp far ptr StopInAnotherSegment Indirect jump Near jump jmp register/memory A 16-bit operand contains the offset of the instruction, at which the program execution shall continue..data Address.CODE Start: Stop: DW Start mov ax,offset Stop jmp ax... jmp Address Assembly Languag 6/ 4

Far jump jmp memory An operand contains the complete address (offset, segment) of the instruction, at which the program execution shall continue; it is of type: dword in 16-bit mode fword in 32-bit mode Data SEGMENT Address DD Continue Data ENDS Program1 SEGMENT ASSUME cs:program1 Continue: xor ax,ax mov ah,4ch int 21h Program1 ENDS Program2 SEGMENT ASSUME cs:program2, ds:data Start: mov ax,data mov ds,ax jmp Address Program2 ENDS END Start Assembly Languag 6/ 5

Conditional jumps They allow to branch program execution according to the flags ZF, CF, SF, PF a OF. jcc label After comparison of unsigned numbers: Instruction Meaning jump if Condition jb jnae below not (above or equal) CF = 1 jc carry jae jnb jnc above or equal not below not carry CF = 0 jbe below or equal jna not above CF = 1 or ZF = 1 ja above jnbe not (below or equal) CF = 0 and ZF = 0 Assembly Languag 6/ 6

After comparison of signed numbers: Instruction Meaning jump if Condition jl less jnge not (greater or equal) SF OF jge greater or equal jnl not less SF = OF jle less or equal jng not above ZF = 1 or SF OF jg jnle greater not (less or equal) ZF = 0 and SF = OF Instruction Meaning jump if Condition je equal jz zero ZF = 1 jne not equal jnz not zero ZF = 0 jp parity jpe parity even PF = 1 jnp not parity jpo parity odd PF = 0 js sign SF = 1 Assembly Languag 6/ 7

jns not sign SF = 0 jo overflow OF = 1 jno not overflow OF = 0 jcxz CX is 0 CX = 0 jecxz ECX is 0 ECX = 0 Conditional jumps must be direct, near and short. cmp al, x je StopFarAhead inc Count cmp al, x jne Continue jmp StopFarAhead Continue: inc Count Assembly Languag 6/ 8

do not change flags. loop label Loop instructions In 16-bit mode, loop decrements register CX and compares it with 0 leaving the flags unchanged. If new CX 0, jumps to the label. Otherwise the program execution continues with the next instruction. Label is at the first instruction of the loop. It must be short. In 32-bit mode, loop decrements and tests register ECX. loope label loopz label - decrement register CX and compare it with 0. If the new contents of register CX 0 a ZF = 1, jump to the label. loopne label loopnz label - decrement register CX and compare it with 0. If the new contents of register CX 0 a ZF = 0, jump to the label. Assembly Languag 6/ 9

Example Read characters typed on the keyboard and store them to variable IOBuffer until ENTER is pressed or MaxNumber characters are typed..model small.stack 100h.DATA MaxNumber EQU 80 IOBuffer DB MaxNumber dup (?).CODE Start: mov ax,@data mov ds,ax mov bx,offset IOBuffer mov cx, MaxNumber jcxz Stop Read: mov ah,1 int 21h; store ASCII code of pressed character to al mov [bx],al inc bx cmp al,0dh; was ENTER? loopnz Read; repeat if not Stop: mov ax,4c00h int 21h END Start Assembly Languag 6/ 10