Assembly programming A little background on using the software.

Slides:



Advertisements
Similar presentations
Introduction to Assembly Language
Advertisements

Code Composer Department of Electrical and Computer Engineering
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 5th Edition
CS2422 Assembly Language and System Programming Assembly Language Fundamentals Department of Computer Science National Tsing Hua University.
MASM CODEVIEW TUTORIALS
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.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Symbolic Constants Equal-Sign Directive Calculating.
Runtime Stack Managed by the CPU, using two registers
Outline Learning Assembly by an Example.  Program Formats  Some Simple Instructions  Assemble and Execute Learning Another Example  Data Definition.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved.
1 Lecture 3: Assembly Language Fundamentals Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language and System Programming Procedures Department of Computer Science National Tsing Hua University.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language & System Programming October 24, 2006.
Coding.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
CS2422 Assembly Language & System Programming September 26, 2006.
Or CMD/BATCH.  Title this comand makes the cmd prompt’s title whatever you would like it to be.
Chapter 2 Software Tools and Assembly Language Syntax.
1/2002JNM Edit, Assemble, Link & Debug. 1/2002JNM Files Created.
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: Assembly Language Fundamentals
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals Assembling, Linking and Running Programs Example Programs.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
®® Microsoft Windows 7 for Power Users Tutorial 13 Using the Command-Line Environment.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
Intro Python: Variables, Indexing, Numbers, Strings.
Assembly Language for Intel-Based Computers, 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Sahar Mosleh California State University San MarcosPage 1 Nested Procedure calls and Flowcharts.
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS, PROCEDURES.
Java Programming, Second Edition Appendix A Working with Java SDK 1.4.
Computer Organization and Assembly Languages Yung-Yu Chuang 2006/11/13
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
CHAPTER 5: PROCEDURES ASSEMBLY LANGUAGE FOR INTEL- BASED COMPUTERS, 5 TH EDITION (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 18 Linking to External Library The Book’s Link Library Stack Operations.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Procedure Computer Organization and Assembly Languages Yung-Yu Chuang 2005/10/27 with slides by Kip Irvine.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
CS2422 Assembly Language and System Programming 0 Week 7 & 8 Intro. To Assembly Programming.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 3: Assembly Language Fundamentals (c) Pearson Education, All rights reserved. You.
Lecture 15 Advanced Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for x86 Processors 6th Edition
Compsci 210 Tutorial Five.
Assembly Language for x86 Processors 6th Edition
Chapter 5: Procedures.
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Microprocessor and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture “Bomb Lab Hints”
Data-Related Operators and Directives
Assembly Programming Notes for Practical 1 1.
Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers, 4th Edition
Introduction Installation of MASM Installation of TextPad
CSC235 - Visual Studio Tutorial
The Stack and Procedures
Hardware & Software Architecture
MUL operation.
More on operators and procedures in the Linked
BASIC SYNTAX OF ASSEMBLY LANGUAGE “HELLO WORLD” PROGRAM.
Presentation transcript:

assembly programming A little background on using the software

Irvine text examples etc The newer text (edition 5) contains chapter examples along with VC++ and uses this MS interface for editing and assembling assembly code. The Irvine assembly text editon #4 contains a CD with a version of the assembler, various batch files, as well as examples in chapter directories. I have this CD and it is on the Math Lab machines for you to copy. The assembler itself may be available in F200 and even in other campus labs.

Machine configuration You will typically create assembly program files using a text editor, so you may want to install Textpad on your own machine. This is shareware and is available from Helios.com. Notepad can also be used. As can VC++. The only other sw needed is on the text CD. (The assembler is part of MS Windows, but is likely buried somewhere so you can’t find it and may not have all versions we will use.) The text assembles and runs programs in the VC environment but I will use DOS.

Assembly is in the labs In the labs, assembler and linker are tools off Textpad. (Currently just 32 bit but I will ask them to add 16 bit). There is a shortcut to your p drive. From here, you can run your program

Entering a program into textpad (in lab)

Selecting tools option “build 32- bit MASM” from textpad in labs Assembling: addsub.asm LINK32 : LNK6004: addsub.exe not found or not built by the last incremental link; performing full link Volume in drive P is Faculty P Drives Volume Serial Number is D Directory of P:\assembly 08/28/ :58 AM 306 addsub.asm 08/28/ :59 AM 28,711 addsub.exe 08/28/ :59 AM 33,324 addsub.ilk 08/28/ :59 AM 15,246 addsub.lst 08/28/ :59 AM 6,938 addsub.map 08/28/ :59 AM 3,714 addsub.obj 08/28/ :58 AM 91,136 addsub.pdb 7 File(s) 179,375 bytes 0 Dir(s) 9,986,265,088 bytes free Tool completed successfully

Looks like this on p drive

Submissions Typically, you’ll submit screenshots of your program assembly/run along with an electronic copy of your code. (see previous slides) Both can be put (pasted) in an html file to which you send me the link.

On your own machine…Run setup on the 4 th edition CD to copy the assembler and text examples to your C drive

Path settings You’ll have to put the assembler in your path settings to assemble and run asm programs, or move the asm files to the directory where masm is located. There are batch files provided which will run masm and then run the linker. These are named make16.bat, make32.bat. Make sure all included files are in the directory from which you are assembling or fix paths appropriately. Make sure all file modules are in the directory from which you link or fix paths appropriately.

extensions.asm marks an asm file. You may use textpad or notepad to create and edit these. Note: You can also configure textpad to assemble and run the code. When writing your own assembly code, at least in the beginning, you may want to cut/paste to start with using one of my or one of the text’s examples, then edit it..obj marks an object file. It must be linked before it can be run. The assembler creates an obj file from an.asm file. The linker resolves symbol references and can create a single exe from several obj files. The first obj in the linker commandline list is the default “main”..exe marks an executable. It can be run by clicking it with the mouse or typing it’s name on the commandline (assuming it is in the path)..lst marks a listing file of the assembly – we won’t use this.

More on how it works Masm.exe creates an.obj file from an.asm file. Link.exe creates an.exe file from a.obj file. The batch files provided assume the proper file-designation extensions. But you will get an error if you type the.asm extension when running the batch files. Use make16.bat to assemble and link a 16-bit format assembly program. Use make32.bat to assemble and link a 32-bit format assembly program. Or run the assembler and linker (exe files) directly, yourself, on the commandline.

Here is a text example (I renamed it example16.asm) TITLE Add and Subtract (16-bit.asm) ; This program adds and subtracts 32-bit integers. ; Last update: 2/1/02 INCLUDE Irvine16.inc.code main PROC mov mov ds,ax mov eax,10000h; EAX = 10000h add eax,40000h; EAX = 50000h sub eax,20000h; EAX = 30000h call DumpRegs exit main ENDP END main

Below I copied the previous16-bit example to my masm directory to run it C:\MASM615>make16 example16 Assembling: example16.asm Volume in drive C has no label. Volume Serial Number is 84F7-99D3 Directory of C:\Masm615 08/18/ :14 AM 343 example16.asm 08/18/ :15 AM 6,824 example16.exe 08/18/ :15 AM 7,961 example16.lst 08/18/ :15 AM 2,424 example16.obj 4 File(s) 17,552 bytes 0 Dir(s) 144,214,294,528 bytes free Press any key to continue... C:\MASM615>example16 EAX= EBX= ECX=000000FF EDX= ESI= EDI= EBP= E ESP= EIP= A EFL= CF=0 SF=0 ZF=0 OF=0 C:\MASM615>

Format and examples Here is another example, a 32 bit assembly program which assigns values to 3 registers and does some simple arithmetic. A procedure (not shown) is used to “dump” register contents to the DOS window. The example shown is from chapter 3.

program from the text shown earlier in textpad : you’ll need to run make32.bat to assemble it. TITLE Add and Subtract (AddSub.asm) ; This program adds and subtracts 32-bit integers. ; Last update: 2/1/02 INCLUDE Irvine32.inc.code main PROC mov eax,10000h; EAX = 10000h add eax,40000h; EAX = 50000h sub eax,20000h; EAX = 30000h call DumpRegs exit main ENDP END main

the blackscreen DOS window: assemble & run the file Assembling: addsub.asm Volume in drive C has no label. Volume Serial Number is 84F7-99D3 Directory of C:\Masm615 8/18/ :23 AM 316 AddSub.asm 8/18/ :24 AM 28,710 addsub.exe 8/18/ :24 AM 33,300 addsub.ilk 8/18/ :24 AM 15,256 addsub.lst 8/18/ :24 AM 6,938 addsub.map 8/18/ :24 AM 3,684 addsub.obj 8/18/ :24 AM 91,136 addsub.pdb 7 File(s) 179,340 bytes 0 Dir(s) 144,214,036,480 bytes free ress any key to continue... :\MASM615>addsub EAX= EBX=7FFDD000 ECX=0012FFB0 EDX=7C90EB94 ESI= EDI= EBP=0012FFF0 ESP=0012FFC4 EIP= EFL= CF=0 SF=0 ZF=0 OF=0

More remarks The 16-bit programs use an include file irvine16.inc and the 32-bit programs use irvine32.inc. These are just text files containing assembly code, but they must be in the current directory for the assembler to find and include them in the listing. We’ll write much of the code they contain as the semester progresses.

A fancier example: Using procedures from Chapt 5 This example uses procedures which the author provides and which are not shown here to read/write ints and write strings. We will use these utilities for quite a while, until we learn to replace them with our own later in the course. They are –writestring –readint –writeint

Fancier example page 1 TITLE IOExamples (IOEx.asm) INCLUDE Irvine32.inc CR = 0Dh; carriage return LF = 0Ah; line feed.data ;;;this is the data for the program prompt2 BYTE "Enter a 32-bit signed int",0 prompt4 BYTE "enter another:",0 result byte "answer is:",0 val1 DWORD ? val2 dword ?

page 2, code section.code main PROC;;start a proc called main ; Set text color to black text on white background: mov eax,black + (white * 16) call SetTextColor call Clrscr; clear the screen mov edx,OFFSET prompt2; "Enter a 32-bit..." call WriteString call ReadInt; input the integer mov val1,eax; save in a variable call Crlf; new line call WriteInt; display in signed decimal mov edx,OFFSET prompt4; "another..." call WriteString call ReadInt; input the integer

page 3, more code mov val2,eax; save in a variable...maybe use it later call Crlf; new line call WriteInt; display in signed decimal call Crlf mov ebx,val1 add eax,ebx mov edx, offset result call WriteString call Crlf; new line call WriteInt; display in signed decimal call Crlf exit main ENDP;;;end a proc named main END main;;name of proc to run when this file is loaded

Output to a white “popup” DOS window Enter a 32-bit signed int enter another: answer is: C:\Masm615\Examples\ch05>

An assembly tutorial I provided a tutorial (link on classpage) detailing how to install the 4 th edition software and examples we will use to your computer, and showing how to run them. If this ppt is not clear, go run the tutorial.