Procedure - Computer Organization and Assembly Language - Lecture Slides, Slides of Assembly Language Programming

This lecture is part of lecture series on Computer Organization and Assembly Language. Main points of this lecture are: Procedure, External Library, Link Library, Stack Operations, Using Procedures, Design Using Procedures, Link Library Overview, Library Procedure, Library Procedures, Containing Procedures

Typology: Slides

2012/2013

Uploaded on 04/25/2013

aristel
aristel 🇺🇸

4.2

(34)

313 documents

1 / 72

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Organization &
Assembly Languages
Procedure
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48

Partial preview of the text

Download Procedure - Computer Organization and Assembly Language - Lecture Slides and more Slides Assembly Language Programming in PDF only on Docsity!

Computer Organization &

Assembly Languages

Procedure

Chapter Overview

 Linking to an External Library

 The Book's Link Library

 Stack Operations

 Defining and Using Procedures

 Program Design Using Procedures

Link Library Overview

 A file containing procedures that have been

compiled into machine code

 constructed from one or more OBJ files

 To build a library,...

 start with one or more ASM source files

 assemble each into an OBJ file

 create an empty library file (extension .LIB)

 add the OBJ file(s) to the library file, using the

Microsoft LIB utility

Calling a Library Procedure

INCLUDE Irvine32.inc .code mov eax,1234h ; input argument call WriteHex ; show hex number call Crlf ; end of line

• Call a library procedure using the CALL instruction.

Some procedures require input arguments. The

INCLUDE directive copies in the procedure

prototypes (declarations).

• The following example displays "1234" on the console:

What's Next

 Linking to an External Library

 The Book's Link Library

 Stack Operations

 Defining and Using Procedures

 Program Design Using Procedures

Library Procedures - Overview

CloseFile – Closes an open disk file

Clrscr - Clears console, locates cursor at upper left corner

CreateOutputFile - Creates new disk file for writing in output mode

Crlf - Writes end of line sequence to standard output

Delay - Pauses program execution for n millisecond interval

DumpMem - Writes block of memory to standard output in hex

DumpRegs – Displays general-purpose registers and flags (hex)

GetCommandtail - Copies command-line args into array of bytes

GetMaxXY - Gets number of cols, rows in console window buffer

GetMseconds - Returns milliseconds elapsed since midnight

Library Procedures - Overview (cont.)

ReadFromFile – Reads input disk file into buffer

ReadDec - Reads 32-bit unsigned decimal integer from keyboard

ReadHex - Reads 32-bit hexadecimal integer from keyboard

ReadInt - Reads 32-bit signed decimal integer from keyboard

ReadKey – Reads character from keyboard input buffer

ReadString - Reads string from standard input, terminated by [Enter]

SetTextColor - Sets foreground and background colors of all

subsequent console text output

StrLength – Returns length of a string

WaitMsg - Displays message, waits for Enter key to be pressed

WriteBin - Writes unsigned 32-bit integer in ASCII binary format.

WriteBinB – Writes binary integer in byte, word, or doubleword format

WriteChar - Writes a single character to standard output

Library Procedures - Overview (cont.)

WriteDec - Writes unsigned 32-bit integer in decimal format

WriteHex - Writes an unsigned 32-bit integer in hexadecimal

format

WriteHexB – Writes byte, word, or doubleword in hexadecimal

format

WriteInt - Writes signed 32-bit integer in decimal format

WriteString - Writes null-terminated string to console window

WriteToFile - Writes buffer to output file

WriteWindowsMsg - Displays most recent error message

generated by MS-Windows

Example 2

.data str1 BYTE "Assembly language is easy!",

.code mov edx,OFFSET str call WriteString call Crlf

Display a null-terminated string and move the cursor

to the beginning of the next screen line.

Example 3

IntVal = 35 .code mov eax,IntVal call WriteBin ; display binary call Crlf call WriteDec ; display decimal call Crlf call WriteHex ; display hexadecimal call Crlf

Display an unsigned integer in binary, decimal, and

hexadecimal, each on a separate line.

Sample output:

Example 5

.code mov ecx,10 ; loop counter

L1: mov eax,100 ; ceiling value call RandomRange ; generate random int call WriteInt ; display signed int call Crlf ; goto next display line loop L1 ; repeat loop

Generate and display ten pseudorandom signed integers

in the range 0 – 99. Pass each integer to WriteInt in EAX

and display it on a separate line.

Example 6

.data str1 BYTE "Color output is easy!",

.code mov eax,yellow + (blue * 16) call SetTextColor mov edx,OFFSET str call WriteString call Crlf

Display a null-terminated string with yellow characters

on a blue background.

The background color is multiplied by 16 before being added to the foreground color.

Stack Operations

 Runtime Stack

 PUSH Operation

 POP Operation

 PUSH and POP Instructions

 Using PUSH and POP

 Example: Reversing a String

 Related Instructions

Runtime Stack

 Imagine a stack of plates...

 plates are only added to the top

 plates are only removed from the top

 LIFO (Last-In, First-Out) structure

 Push & pop operations

1

2

3

4

5

6

7

8

9

10 top

bottom