Constants and. Lecture 7: Assembly Language Programs. Expressions (cont.) Constants and. Statements. Expressions

Similar documents
Constants and Expressions. Lecture 7: Assembly Language Programs. Constants and Expressions (cont.) Statements. Names. Assembly Directives

Assembly Language Fundamentals. Chapter 3

Lab 3: Defining Data and Symbolic Constants

Experiment 3 3 Basic Input Output

8086 ALP TOOLS (CH 2) CHAPTER 2

Lab 4: Basic Instructions and Addressing Modes

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

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

LAB WORK NO. 3 TURBO DEBUGGER ENVIRONMENT

Basic Assembly SYSC-3006

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

Experiment N o 3. Segmentation and Addressing Modes

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

Experiment N o 3 Segmentation and Addressing Modes

ORG ; TWO. Assembly Language Programming

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

CSE 505 Lecture 8: Introduction to Assembly Language

Computer Architecture and System Software Lecture 07: Assembly Language Programming

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

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics

CPU. IBM PC and compatible Memory Structure

ELEC 242 Using Library Procedures

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

EC 333 Microprocessor and Interfacing Techniques (3+1)

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

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 3: Assembly Language Fundamentals

Computer Architecture and System Software Lecture 06: Assembly Language Programming

Chapter 3: Addressing Modes

Computer Architecture 1 ح 303

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

Experiment #2. Addressing Modes and Data Transfer using TASM

Assembly basics CS 2XA3. Term I, 2017/18

Assembly Language LAB

Lab 2: Introduction to Assembly Language Programming

Mating Assembly with C

EEM336 Microprocessors I. Data Movement Instructions

EC-333 Microprocessor and Interfacing Techniques

Assembly Language LAB

Assembly Language. Lecture 3 Assembly Fundamentals

Assembly Language: g Part III. First Semester 2013 Department of Computer Science Faculty of Science Chiang Mai University

Course Syllabus [1/2]

Intel 8086: Instruction Set

Come and join us at WebLyceum

Assembly Language Programming

Chapter 3: Assembly Language Fundamentals. Cristina G. Rivera

X86 Assembly Language and C Fundamentals. Chapter 5. Data Transfer Instructions. X86 Code Figures

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

Defining and Using Simple Data Types

Experiment N o 1. Introduction to Assembly Language Programming

Experiment 8 8 Subroutine Handling Instructions and Macros

Data Transfers, Addressing, and Arithmetic. Part 2

MICROPROCESSOR TECHNOLOGY

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

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

Assembly Language for Intel-Based Computers, 5 th Edition. Kip Irvine. Chapter 3: Assembly Language Fundamentals

Computer Architecture and System Software Lecture 04: Floating Points & Intro to Assembly

How to write an assembly language program.

IBM PC Hardware CPU 8088, Pentium... ALU (Arithmetic and Logic Unit) Registers. CU (Control Unit) IP.

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

Lab 6: Conditional Processing

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Printing this Slide Show

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

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

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

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

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

Computer Organization and Assembly Language. Lab Session 4

Assembly Language for Intel-Based Computers, 5 th Edition. Chapter 3: Assembly Language Fundamentals

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

Ethical Hacking. Assembly Language Tutorial

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

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

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

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

Assembly Language for Intel-Based Computers, 5 th Edition

Lecture (05) x86 programming 4

Summer 2003 Lecture 15 07/03/03

Lecture 13: I/O I/O. Interrupts. How?

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

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

3- ADDRESSING MODES in 8086: In this section we use the MOV instruction to describe the data-addressing modes. Figure 3-1 shows the MOV instruction.

Assembly Fundamentals

CS-202 Microprocessor and Assembly Language

By: Dalbir Singh, Computer Science Dep't

Conditional Processing

Experiment N o 1. 1 Introduction to Assembly Language Programming

16.317: Microprocessor Systems Design I Fall 2013

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

Assembly Language Lab # 9

EE 314 Spring 2003 Microprocessor Systems

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 3: Assembly Language Fundamentals.

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

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

Philadelphia University Student Name: Student Number:

ELEC 242 Time Delay Procedure

Lab 5: Input/Output using a Library of Procedures

Introduction to Assembly Language

CS499. Intel Architecture

Computer Organization and Assembly Language. Lab Session 01

Transcription:

Lecture 7: Assembly Language Programs Basic elements of assembly language Assembler directives Data allocation directives Data movement instructions Assembling, linking, and debugging Using TASM Constants and Expressions (cont.) constant expression symbolic constant Character or string constants Constants and Expressions Numeric literal: Integer constants end with a radix symbol h (hex), q or o (octal), d (decimal), b (binary). Statements [name][mnemonic][operands][;comment] Free-form any column, any number of spaces, can use blank lines Two types of statements: Instruction statements executed by the processor at run-time. Directives statements that give instructions to the assembler. 1

Names Four types of names: Variable: Label: Symbol: Keyword: Case-insensitive Can t start with digits (and should avoid starting with @) Can t match a reserved word Program Structure Using Directives title <your title here>.model small.stack 100h <your data here> main proc mov ax, @data mov ds,ax <your code here> main endp end main Assembly Directives marks start of code segment marks start of data segment.stack set the size of the stack segment.model specify memory model (we will use.model small 64K for memory, 64K for data) title title of listing file proc begin procedure endp end of procedure end end of program page set page format Alternative Structure title <your title here>.model small.stack 100h <your data here>.startup <your code here>.exit end.startup and.exit are always used in a pair..startup sets up the data segment so you don t need to do it! 2

Data Allocation Directives Data allocation directives allocate storage based on several predefined types: DB define byte (1 byte) DW define word (2 bytes) DD define doubleword (4 bytes) and more for larger data types (up to 10 bytes) DB Example alist db ABCD offset contents 0000 A 0001 B 0002 C 0003 D Define Byte (DB) Example: char1 db A ;ASCII character char2 db A 10 ; expression signed1 db 128 ;smallest signed val signed2 db +127 ;largest signed val unsig1 db 255 ;largest unsigned val Multiple initializers: list db 1, 2, 3, 4 Strings: mystring db Hello World,0 Can duplicate values using DUP: db 2 dup( ABC ) ; 6 bytes ABCABC Define Word (DW) Example: dw 0, 65535 ;smallest/largest unsigned vals dw 32768, 32767 ;smallest/largest signed dw 256 * 2 ;calc expression (512) dw 1000h, 4094, AB ; multiple initializers dw? ;uninitialized dw 5 dup(1000h) ; 5 words, each 1000h dw 5 dup(?) ;5 words, uninitialized Pointer the offset of a variable or subroutine can be stored in another variable (a pointer): list dw 23, 45, 22, 34 ptr dw list Reversed storage format 3

DW Example MOV Instruction code: msg dw 'SC','02','11','L ', 'ba','1 ' data in memory: -d 131d:0 131D:0000 43 53 32 30 31 31 20 4C-61 62 20 31 2B D3 E8 DB CS2011 Lab 1+... MOV destination, source Basic forms: MOV reg, reg MOV mem, reg MOV reg, mem MOV mem, immed MOV reg, immed Notice: no move from memory to memory! Define Doubleword (DD) Examples: signed_val dd 0, 0BCDA1234h, -2147483648 block dd 100h dup(?) ; 256 doublewords (1024 bytes) Bytes in a doubleword are stored in reverse order least significant digits at the lowest offset. 12345678h: Offset: 00 01 02 03 Value: 78 56 34 12 Doublewords can hold the 32-bit segment-offset address of a variable or procedure: pointer dd subroutine1 MOV Examples count db 10 total dw 4126h bigval dd 12345678h mov al, bl ;8-bit register to register mov bl, count ; 8-bit memory to register mov count,26 ; 8-bit immediate to memory mov bl, 1 ;8-bit immediate to register mov dx, cx ; 16-bit register to register mov bx, 8FE2h ;16-bit immediate to register mov total, 1000h ;16-bit immediate to memory mov eax, ebx ; 32-bit register to register mov edx, bigval ;32-bit memory to register 4

Type Checking Assembler uses the size you give the variable: count dw 20h mov al, count ; error The LABEL attribute: countb label byte ; byte attribute countw dw 20h ; word attribute mov al, countb ; get low byte mov cx, countw ; get whole thing XCHG XCHG exchanges the contents of two registers or a register and a variable: XCHG reg, reg XCHG reg, mem XCHG mem, reg Operands with Displacements You can add a displacement to the name of a variable using directoffset addressing. Example: arrayb db 10h, 20h arrayw dw 100h, 200h. mov al, arrayb ;AL = 10h mov al, arrayb+1 ;AL = 20h mov ax, arrayw ;AX = 100h mov ax, arrayw+2 ;AX = 200h mov ax, arrayw+1 ;AX =? XCHG Example adding two variables from p. 73 of Irvine. 5

Assembling, Linking, and Debugging Multi-step process: Use a text editor to create a source file. Use the assembler program to read the source file and create an object file. Use the linker to link the object file with any needed routines from the link library and create an executable program. Use the operating system to run the executable. Assembling using TASM Without errors: D:\Janet\Teaching\CS2011\Labs>tasm/z/zi lab1.asm Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International Assembling file: lab1.asm Error messages: None Warning messages: None Passes: 1 Remaining memory: 418k z option source lines with errors should be displayed. zi option include information needed by the debugger in the output file. Assemble-Link-Execute Cycle figure 1 from p. 60 of Irvine Table 2 from p. 61 of Irvine Assembling using TASM, cont. With errors: D:\Janet\Teaching\CS2011\Labs>tasm/z/zi lab1.asm Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International Assembling file: lab1.asm mov AX, [mst] **Error** lab1.asm(11) Undefined symbol: MST Error messages: 1 Warning messages: None Passes: 1 Remaining memory: 418k 6

Linking using TASM Tracing Programs D:\Janet\Teaching\CS2011\Labs>tlink/v lab1 Turbo Link Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International /v option indicates that debug options should be included. Other options: /3 allow 32 bit registers (we won t be using this) /m generate a map file Some useful windows for looking at program information: Stack Window (View/Stack) lists all active procedures with most recent called listed first. This tells you how you got to where you are. Execution History Window this keeps a record of the last 400-3000 instructions executed! Debugging using TASM Tracing Programs, cont. Use debugging options when assembling and linking Debugging information is stored in the.obj and.exe files, making them slightly larger. Starting the turbo debugger: td lab1 Stepping through your program: run (F9) runs through the program to the end, a breakpoint, or until ctrl-break is pressed go to cursor (F4) runs and stops before the line the cursor is on is executed trace into (F7) a single-step through the program that steps into subroutines step over (F8) a single-step through the program that skips over procedure calls (executing the procedure). This fully executes LOOP and INT instructions see p. 616 of Irvine for more! 7

Breakpoints Breakpoints are very useful! A breakpoint is a marker that tells the debugger to pause in one of the following ways: unconditionally on a particular statement when a pre-set condition becomes true (say on the 3 rd time through a loop) when a memory location changes see Irvine p. 617 for things you can do with breakpoints. Examining and Modifying Data There are many ways to examine and modify data using the debugger: examining registers (View/Registers) examine and modify variables (View/Variables) watch windows (View/Watches) allow you to watch variables change as the program runs view memory (View/Dump) getting a hex memory dump (like we did in debug) Be sure to read Appendix D on how to use the Turbo Debugger! 8