Assembly Programming Notes for Practical 1 1.

Slides:



Advertisements
Similar presentations
Register In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than.
Advertisements

Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
There are two types of addressing schemes:
Assembly Programming Notes for Practical2 Munaf Sheikh
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#3) By Dr. Syed Noman.
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
Lecture 6 Machine Code: How the CPU is programmed.
Lab6 – Debug Assembly Language Lab
Which Version of MASM are you Using? Like most function files, the MASM.exe file is constantly updated. In production, typically some date is chosen as.
Princess Sumaya University
Outline Learning Assembly by an Example.  Program Formats  Some Simple Instructions  Assemble and Execute Learning Another Example  Data Definition.
Assembly Language Advantages 1. It reveals the secret of your computer’s hardware and software. 2. Speed. 3. Some special applications and occasions. Disadvantages.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
CS2422 Assembly Language & System Programming September 26, 2006.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Chapter 2 Software Tools and Assembly Language Syntax.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Chapter 1: Basic Concepts
Types of Registers (8086 Microprocessor Based)
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
Assembly Programming Notes for Practical 1
Review of Assembly language. Recalling main concepts.
University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Internal Programming Architecture or Model
Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
Assembly language programming
Assembly language.
Instruction set Architecture
Assembly Language for x86 Processors 6th Edition
Format of Assembly language
8086 Microprocessor.
Computer Organization & Assembly Language Chapter 3
Additional Assembly Programming Concepts
ADDRESSING MODES.
16.317: Microprocessor System Design I
Microprocessor Systems Design I
Microprocessor and Assembly Language
ADDRESSING MODES.
University of Gujrat Department of Computer Science
1st micro 1971 calculator 2300 transistors 4-bit microprocessor
Microprocessor Lab CSL1543 0:0:2
(The Stack and Procedures)
Assembly Lang. – Intel 8086 Addressing modes – 1
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
Introduction to Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
8086 Registers Module M14.2 Sections 9.2, 10.1.
CS-401 Computer Architecture & Assembly Language Programming
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
CS 301 Fall 2002 Computer Organization
(The Stack and Procedures)
Symbolic Instruction and Addressing
CNET 315 Microprocessor & Assembly Language
Lecture 06 Programming language.
Computer Architecture CST 250
Microprocessor and Assembly Language
Unit-I 80386DX Architecture
Chapter 6 –Symbolic Instruction and Addressing
Process.
(The Stack and Procedures)
Intel 8086.
Chapter 8: Instruction Set 8086 CPU Architecture
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

Assembly Programming Notes for Practical 1 1

COS212 Architecture Lecturer: Prof IM Venter Practical Assistants: Andre Henney, Toufeeq Allie & Andries Kruger

About the Practicals Covering the Assembly Language Assembly for Intel-Based Computers Fourth edition Kip R. Irvine Also the slides help a lot and check website 7 Practicals Consult Course outline for dates and website for more information http://www.cs.uwc.ac.za/~iventer/Courses/csc212/Course%20Description.htm Practicals 3rd, 4th and 5th period every Wednesday. Homework Due Next Wednesday NO late Submissions Expect Surprise Tests

Programming Languages

Machine Language "... is a numeric language that is specifically understood by computer's processor (CPU)..." - consists purely of numbers: eg: 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 1011000000000101 WHAT DOES THAT MEAN? 5

What is Assembly Language? A programming language that is easier for humans to understand, but slightly less efficient for computers to process. Uses names and hexadecimal pointers instead of binary numbers. 6

What is Assembly Language? (cont)‏ A machine-orientated language in which mnemonics are used to represent each machine-language instruction. E.g. ADD, MOV, SUB, MUL etc, which represent machine language sequences (011000)‏

Translating Languages English: Display the sum of A times B plus C. Java: System.out.println(A * B + C); Assembly Language: mov ax,A mul B add ax,C call WriteInt Intel Machine Language: A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000 8

Download Prac 1 Go to www.cs.uwc.ac.za/~masm/ Download Masm615.exe Right click on Masm615.exe and select save link as Save the file to C:/ Install Masm615, by double left click on executable 9

Starting Dos Click On Start Then type CMD Create a Prac 1 folder on C:\ or n your flash drive (recommended). On MS-DOS prompt, type the command C:\> mkdir prac1 and press Enter. Create and save your practical 1 files in Prac1 folder. 10

A full program looks like: 11

What is a Batch file? Similar to a Makefile in unix It is a text file with the extension .BAT that contains DOS commands. Reduces repetitive typing by executing a batch of commands. 12

Make32 Make32.bat To Compile: make32.bat “filename” in CMD. Note: Remove (omit) the .asm extension 13

Make32 Make32 /Zi filename.asm ; include debugging information Make32 /Fl filename.asm ; produce a listing file (prac1.lst) Make32 /Fm filename.asm ; produce a map file (prac1.map) Make32 /Zm filename.asm ; use MASM 5.12 compatibility mode 14

Make32 The following command assembles filename.asm and links filename.obj to the link library linkfile.lib in the C:\MASM615 directory: Make32 /Zi /Zm /Fm /Fl filename.asm /link /co c:\MASM615\<linkfile> 15

Hello World Open Notepad / Notepad++ / Textpad Select File – Save As Save as type – All Files File name “hello”.asm Save the file in prac1 16

Why Assembly language? Java: public class Hello{ public static void main(String[] args){ System.out.println("Hello World"); } C++: int main(void){ cout << "Hello world\n" << endl; Java and C++ obviously much easier; so why? 17

Hello World title Hello World programme ; ALWAYS include the following lines ; Name: <Dane Brown> (Replace with your own name) ; Purpose: This program displays "Hello world" ; Date: <Today's date> (Insert todays date) include irvine32.inc ; from Irvine CDROM 18

Hello World stack 100h .data HelloString db "Hello, world", 0 ;message to write .code main proc 19

Hello World mov edx, offset HelloString invoke WriteString ; Write to cmd exit ; irvine.inc: a macro that calls ExitProcess main endp end main 20

Possible Instructions Copy Move Delete (del)‏

GOOD LUCK! The Basics are over The next few slides explain registers in detail and can be read in your own time. GOOD LUCK!

Segment Registers CS Code Segment 32-bit number that points to the active code-segment DS Data Segment 32-bit number that points to the active data-segment SS Stack Segment 32-bit number that points to the active stack-segment ES Extra Segment 32-bit number that points to the active extra-segment 23

Pointer Registers IP Instruction Pointer 32-bit number that points to the offset of the next instruction SP Stack Pointer 32-bit number that points to the offset that the stack is using BP Base Pointer used to pass data to and from the stack 24

General-Purpose Registers AX Accumulator Register mostly used for calculations and for input/output BX Base Register Only register that can be used as an index CX Count Register used for the loop instruction DX Data Register input/output and used by multiply and divide 25

Index Registers SI Source Index used by string operations as source DI Destination Index used by string operations as destination 26

Explanation: .model small : Lines that start with a "." are used to provide the assembler with information. The word(s) behind it say what kind of info. In this case it just tells the assembler the program is small and doesn't need a lot of memory. I'll get back on this later. .stack : Another line with info. This one tells the assembler that the "stack" segment starts here. The stack is used to store temporary data. It isn't used in the program, but it must be there, because we make an .EXE file and these files MUST have a stack. 27

Explanation: .data : indicates that the data segment starts here and that the stack segment ends there. .code : indicates that the code segment starts there and the data segment ends there. main proc : Code must be in procedures, just like in Java or any other language. This indicates a procedure called main starts here. main endp states that the procedure is finished. Procedures MUST have a start and end. end main : tells the assembler that the program is finished. It also tells the assembler were to start the program. At the procedure called main in this case. 28

Explanation: message db "xxxx" : DB means Define Byte and so it does. In the data-segment it defines a couple of bytes. These bytes contain the information between the brackets. "Message" is a name to indentify this byte-string. It's called an "identifier".mov ax, seg message : AX is a register. 29

Explanation: MOV is an instruction that moves data. It can have a few "operands". Here the operands are AX and seg message. Seg message can be seen as a number. It's the number of the segment "message" is in (The data-segment) We have to know this number, so we can load the DS register with it. Else we can't get to the bit-string in memory. We need to know WHERE the bit- string is located in memory. The number is loaded in the AX register. MOV always moves data to the operand left of the comma and from the operand right of the comma. 30

Explanation: mov ds,ax : The MOV instruction again. Here it moves the number in the AX register (the number of the data segment) into the DS register. We have to load this DS register this way (with two instructions) Just typing: "mov ds,segment message" isn't possible. mov ah, 09 : MOV again. This time it load the AH register with the constant value nine.

Explanation: lea dx, message : LEA Load Effective Address. This instructions stores the offset within the datasegment of the bit-string message into the DX register. This offset is the second thing we need to know, when we want to know where "message" is in the memory. So now we have DS:DX. See the segment explanation above.