Assembly Lab 3.

Slides:



Advertisements
Similar presentations
Introduction to Assembly Language
Advertisements

COMP 2003: Assembly Language and Digital Logic
Department of Computer Science and Software Engineering
Outline Learning Assembly by an Example.  Program Formats  Some Simple Instructions  Assemble and Execute Learning Another Example  Data Definition.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Intrinsic Data Types (1 of 2) BYTE, SBYTE 8-bit unsigned.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Assembly Language for Intel-Based Computers Chapter 3: Assembly Language Fundamentals Kip Irvine.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
CS2422 Assembly Language & System Programming September 26, 2006.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Chapter 2 Software Tools and Assembly Language Syntax.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
1/2002JNM1 Basic Elements of Assembly Language Integer Constants –If no radix is given, the integer is assumed to be decimal. Int 21h  Int 21 –A hexadecimal.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Introduction to 8086 Assembly Language Assembly Language Programming University of Akron Dr. Tim Margush.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Faculty of Engineering, Electrical Department,
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Chapter Five–80x86 Assembly program development Principles of Microcomputers 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 2015年11月15日 1.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
1 The Stack and Procedures Chapter 5. 2 A Process in Virtual Memory  This is how a process is placed into its virtual addressable space  The code is.
Review of Assembly language. Recalling main concepts.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
CS2422 Assembly Language and System Programming 0 Week 7 & 8 Intro. To Assembly Programming.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
1 Chapter 3 Assembly Language Fundamentals Assembly Language for Intel-Based Computers, 4th edition Revised 3/11/05.
Stack Operations Dr. Hadi AL Saadi.
Assembly Language for x86 Processors 6th Edition
Assembly language programming
Assembly language.
Instruction set Architecture
Format of Assembly language
x86 Assembly Language Fundamentals
Additional Assembly Programming Concepts
16.317: Microprocessor System Design I
Microprocessor Systems Design I
Assembly IA-32.
INTRODUCTION ABOUT ASSEMBLY
Assembly Language for Intel-Based Computers, 5th Edition
Defining Types of data expression Dn [name] expression Dn [name]
Introduction to Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Data-Related Operators and Directives
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Assembly Language for Intel-Based Computers
Requirements for coding in Assembly Language
Assembler Directives end label end of program, label is entry point
Hardware & Software Architecture
Division instruction.
Introduction to 8086 Assembly Language
Computer Architecture and System Programming Laboratory
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

Assembly Lab 3

Agenda First Assembly Program. Modified Assembly Skeleton. Basic Instructions. Defining Data Items. Little Indian Vs Big Indian . Addressing Modes.

First Assembly Program Assembly language program is a series of statements which are either computer instructions or statements called directives. Each assembly instruction represents exactly one machine instruction. However, directives do not generate any machine code. The general form of an assembly instruction is: [label:] mnemonic [operands] [;comment]

First Assembly Program .DATA, .CODE, and .STACK directives are used to express the starting of data, code, and stack segments respectively. Data segment is used to define program data. Stack segment is used to store data temporarily like saving registers values in the beginning of procedure call. Code segment contains the program instructions that do the required work.

General Program Skeleton .386 .MODEL Flat, STDCALL .STACK 4096 .DATA ;Your initialized data .CODE <label> ;Your code ret END <label>

Modified Skeleton Program INCLUDE Irvine32.inc .data .code main: ;define a label main exit ;terminate the execution of the program END main ;end the assembler work, and make the main as program entry point

Basic Instructions mov dest, src Examples: mov eax, 3 It moves data from one location to another It takes two operands. mov dest, src Note: dest and src must have the same size and both should not be memory operands Examples: mov eax, 3 ; eax register will have value 3 mov bx, ax ; bx will have the value that was in ax

Basic Instructions Examples: add eax, 4 add al, ah ; eax = eax + 4 It’s used to add integers. It takes two operands. Examples: add eax, 4 ; eax = eax + 4 add al, ah ; al = al + ah

Debugging Demo

Defining Data Items [name] Type initialization variable name To define a variable [name] Type initialization variable name Unsigned Signed Size (in bytes) BYTE SBYTE 1 WORD SWORD 2 DWORD SDWORD 4 QWORD 8 TBYTE 10

Initialization of variables Should fit into the variable size Can be a single value or a comma‐separated list of values and in this case the variable will refer to an array of these values. If there is no specific initial value for that variable, you just put a question mark ‘?’.

Initialization example Integer constant 2 33d 1CEh 1010100b, ‐5 d: decimal h: hexadecimal b: binary - Decimal is the default - Negative numbers are stored in 2’s comp. form String constant ‘A’ , “F” ‘Hello’,“Hello” It is often used with BYTE data type Integer expression 3+4, 6*5‐3 The result of the integer expression should fit the size of the variable

Arrays Arrays can be defined either by : 1- Comma separated values as specified before. 2- [name] Type repeat-count Dup (initialization) Repeat‐Count specifies the number of items in the array and initialization is the initial value for each item. If the initialization is a single value then every item will be initialized by this value. However, if it is a list, then each item in the array will take the corresponding initial value from the list.

Examples ByteVal0 BYTE ? ByteVal1 BYTE 48 ByteVal2 BYTE 30H ByteVal5 BYTE 'Hello' ByteVal6 BYTE 'H','e','l','l','o'

ByteVal0 BYTE ? ;Un-initialized byte ByteVal1 BYTE 48 ;Decimal value ByteVal2 BYTE 30H ;Hexadecimal value ByteVal3 BYTE 01010110B ;Binary value ByteVal4 BYTE 1, 2, 3, 4 ;Define 4-items array of ;size byte ByteVal5 BYTE 'Hello' ;character string ByteVal6 BYTE 'H','e','l','l','o’ ;list of characters and it’s ;equivalent to the ;previous character ; string‘Hello’

Examples Cont. ByteVal7 BYTE 5 Dup(3) ByteVal8 BYTE 3 Dup(1,2,3) WordVal0 WORD ? WordVal1 WORD 0FF30H WordVal2 WORD 65, 310 WordVal3 WORD 10 Dup(43) DWordVal0 DWORD ? DWordVal1 DWORD 6F34A030H DWordVal2 DWORD 69065, 350, 65 DWordVal3 DWORD 5 Dup(?)

ByteVal7 BYTE 5 Dup(3) ;Define 5-items array each item ; initialized by value = 3 ByteVal8 BYTE 3 Dup(1,2,3) ;3-items array and initialized as 1,2,3 WordVal0 WORD ? ;uninitialized word WordVal1 WORD 0FF30H ;Hexadecimal value WordVal2 WORD 65, 310 ;Define 2-words array WordVal3 WORD 10 Dup(43) ;Define 10-words array each item ;initialized by value = 43 DWordVal0 DWORD ? ;uninitialized double word DWordVal1 DWORD 6F34A030H ;Hexdecimal value DWordVal2 DWORD 69065, 350, 65 ;Define 3 double words array DWordVal3 DWORD 5 Dup(?) ;Define 5 double Words array ;without initializing its items

Hex Values note Example, When specifying a hexadecimal value that begins with a letter (A‐F), you have to put a zero at the begging Example, Hexval: WORD E123h ;Error: assembler thinks E123h is a label Hexval: WORD 0E123h ;correct: as labels never starts with number

Symbolic Constants Symbols are named constants symbol equ value it cannot be modified by any instruction within the program Example: PI_VALUE equ 3.14

Little Indian Vs Big Indian How are multi-byte values (WORD, DWORD, …. etc) are stored in memory. Intel uses little indian Little Indian Big Indean Least significant byte is stored in the lowest address byte while the most significant byte is stored in the highest address byte Most significant byte is stored in the lowest address byte while the least significant byte is stored in Val1 DWORD 12345678h Offset Value Offset Value 100: 78h 100: 12h 101: 56h 101: 34h 102: 34h 102: 56h 103: 12h 103: 78h

Addressing Modes The instruction operands can reside whether in a register or in memory. Addressing modes in Intel assembly language are: 1- Register Addressing: using register name MOV AX, DX 2. Immediate Addressing (source operand only) by specifying the operand value MOV EAX, 23

Addressing Modes Cont. 3. Direct memory Addressing: using the variable name MOV AX, mem_var 4. Direct Offset Addressing MOV CL, byteArr[2] MOV CL, [byteArr+2] MOV CL, byteArr+2.

5. Indirect memory Addressing uses register value as the operand address (not the operand value). Base registers (EBX, EBP), index registers (ESI, EDI) and other general registers (EAX, ECX, EDX) can be used to reference to memory items by their addresses. Register value is considered to be the offset address within a segment. All registers are associated with data segment except EBP associated with stack segment. MOV BX, [ESI] • Base Displacement Addressing MOV ECX, [EBX+3] • Base‐Index Addressing MOV DX, [EBX+ESI] • Base‐Index with Displacement Addressing MOV AX, [EBX+ESI+4]

Addressing mode example

Hands On

Assignment