0% found this document useful (0 votes)
15 views

Lecture Slides Week5 1

This document provides an overview of a course on computer organization and assembly language programming. It outlines the software and tools needed, including an assembler, debugger, and DOS emulator. It then walks through writing a simple assembly language program to add three numbers as an example. The program is assembled and run in a debugger to observe how it works. Finally, it describes the main internal registers of the 8086/8088 CPU, including general purpose, index, stack/base pointers, and instruction pointer registers.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lecture Slides Week5 1

This document provides an overview of a course on computer organization and assembly language programming. It outlines the software and tools needed, including an assembler, debugger, and DOS emulator. It then walks through writing a simple assembly language program to add three numbers as an example. The program is assembled and run in a debugger to observe how it works. Finally, it describes the main internal registers of the 8086/8088 CPU, including general purpose, index, stack/base pointers, and instruction pointer registers.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Computer Organization and Assembly Language

(CS2523)

Week 5 (Chapter 1, Assembly Language Programming Lecture Notes)

Department of Computer Science


Capital University of Science and Technology (CUST)
Outline
• Software Setup
• Our first program
• How to use AFD
• Internal Registers of 8086/8088

2
Software Needed
• Notepad (for writing programs)
• NASM (Assembler). Netwide Assembler
• AFD (Debugger). Advanced Full-screen Debugger
• DOSBox (DOS emulator)

3
Software Setup (only one time)
1.Download the DOS version of nasm (Netwide Assembler) from here
1. We could have used Windows version as it can be used directly in
windows. However if you have 64 bit windows, you will not be able
to use the AFD debugger as the only available version for AFD
debugger is 32-bit. So we will use DOS version of nasm Assembler
with an emulator called DOSBox.

2.Unzip nasm folder to a drive (C: or D:). Rename it to "Assembly-DOS".

3.Copy AFD.exe to the folder "Assembly-DOS". AFD is the debugger (to


view program execution). Download AFD.exe from here. AFD Tutorial can
be downloaded from here.

4.Download and Install DOSBox from here

4
DOSBox
• https://www.dosbox.com
• DOSBox is a DOS-emulator
• DOSBox emulates CPU:286/386 realmode/protected mode,
Directory FileSystem/XMS/EMS, Tandy/ Hercules/ CGA/ EGA
/VGA/ VESA graphics, a SoundBlaster/Gravis Ultra Sound
card for excellent sound compatibility with older games...

5
How to run a program?
1.Write your program in notepad. Save your program file to the “Assembly-
DOS” folder using .asm extension
1. (e.g. file name is "ex01.asm").

2.Run DOSBox and mount the folder "Assembly-DOS" as a drive using the
following command. Here D:\Assembly-DOS is the path to the folder
mount X D:\Assembly-DOS

3.Navigate to Assembly-DOS folder (drive X) from DOSBox by writing the


following command
X:

4.Use the following command to assemble the program


nasm ex01.asm –o ex01.com –l ex01.lst

5.Use the following command to run the program


afd ex01.com
6
Our first program
• The first program that we will write will only add
three numbers.
• It will clarify most of the basic concepts of assembly
language.
• In plain English, the steps of our program are listed
below.

7
8
Details of Instructions used

9
Listing File and Executable File
• When we use the command to assemble a
program, it produces a listing file and an executable
file
• nasm ex01.asm –o ex01.com –l ex01.lst
• ex01.com is the executable file
• Ex01.lst is the listing file

10
Listing file for our program

11
Description
• The first column is offset of the listed instruction in the output file.
• Next column is the opcode into which our instruction was
translated. In this case this opcode is B8.
• Whenever we move a constant into AX register the opcode B8 will be
used.
• After it 0500 is appended which is the immediate operand to this
instruction.
• An immediate operand is an operand which is placed directly inside the
instruction.
• As the AX register is a word sized register (2 bytes or 16 bits), and
one hexadecimal digit takes 4 bits so 4 hexadecimal digits make one
word or two bytes.
• This is actually 0005 but intel uses little endian so in the memory it
is 0500
12
Description Cont…
• As the first instruction is three bytes long, the listing file
shows that the offset of the next instruction in the file is 3.
• The opcode BB is for moving a constant into the BX register,
and the operand 0A00 is the number 10 in little-endian
• Similarly the offsets and opcodes of the remaining
instructions are shown in order.
• The last instruction is placed at offset 0x10 or 16 in decimal.
• The size of the last instruction is two bytes, so the size of the
complete COM file becomes 18 bytes.
• This can be verified from the directory listing, using the DIR
command, that the COM file produced is exactly 18 bytes
long.
13
Executing the Program inside
Debugger
• Now the program is ready to be run inside the
debugger.
• The debugger shows the values of registers, flags,
stack, our code, and one or two areas of the system
memory as data.
• Debugger allows us to step through our program
one instruction at a time and observe its effect on
the registers and program data.
• Use F1 and F2 to step through the program

14
AFD screen with our program

15
Description
• After loading the program in the debugger observe that the first instruction
is now at 0100 instead of absolute zero. This is the effect of the org
directive at the start of our program. The first instruction of a COM file
must be at offset 0100 (decimal 255) as a requirement.
• Also observe that the debugger is showing your program even though it
was provided only the COM file. The debugger mapped back from the
opcode to the instruction mnemonic. This will become apparent for
instructions that have two mnemonics as the debugger might not show the
one that was written in the source file.
• As a result of program execution either registers or memory will change.
• Since our program yet doesn’t touch memory the only changes will be in
the registers.
• Keenly observe the registers AX, BX, and IP change after every instruction.
• IP will change after every instruction to point to the next instruction while
AX will accumulate the result of our addition.
16
AFD Description

17
Parts of the AFD Screen

18
To move between various parts of
AFD
• To Move between memory/data window 2,
registers and command prompt press F7 or F8,
• To go to and come back from data window 1 press
F9

19
To load contents of Memory
• CMD> M1 DS : 100
• The above mentioned command will display the
contents of memory location at offset address
"0x0100" in memory window 1

20
Changing the Values of registers
• If you want to change the values of the registers
directly, you can use the following command
• register=value
• For example, you want to set 1DD0 in DS register,
you will write like this: ds=1DD0 and press Enter

21
Changing content of memory
• To change the contents of the memory, Press F8 or
F9 to go to memory area 1 or memory area 2
• Go to the desired location with arrow keys and type
the new value
• After typing the new value press enter.

22
How to Exit
• Use quit command to exit from the shell.
• On DOS command prompt type cls and press Enter
to clear the screen

23
Registers of 8086/8088

24
Internal Registers of 8086/8088

25
General Registers (AX, BX, CX,
and DX)
• The registers AX, BX, CX, and DX behave as general purpose registers in Intel
architecture and do some specific functions in addition to it.
• X in their names stand for extended meaning 16bit registers.
• All general purpose registers can be accessed as one 16bit register or as two
8bit registers.
• For example the two registers AH and AL are part of AX.
• The A of AX stands for Accumulator. Even though all general purpose registers
can act as accumulator in most instructions there are some specific variations
which can only work on AX which is why it is named the accumulator.
• The B of BX stands for Base because of its role in memory addressing as
discussed in the next chapter.
• The C of CX stands for Counter as there are certain instructions that work
with an automatic count in the CX register.
• The D of DX stands for Destination as it acts as the destination in I/O
operations.
26
Instruction Pointer (IP)
• This is the special register containing the address of
the next instruction to be executed.
• It is out of our direct control and is automatically
used.
• Program control instructions change the IP register.

27
Index Registers (SI and DI)
• SI and DI stand for source index and destination index
respectively.
• These are the index registers of the Intel architecture which
hold address of data and are used in memory access.
• Intel allows many mathematical and logical operations on
these registers
• The source and destination are named because of their
implied functionality as the source or the destination in a
special class of instructions called the string instructions.
• SI and DI are 16bit and cannot be used as 8bit register pairs
like AX, BX, CX, and DX.

28
Stack and Base Pointer (SP and
BP)
• Stack Pointer (SP) is a memory pointer and is used
indirectly by a set of instructions. This register will
be explored in the discussion of the system stack.
• Base Pointer (BP) is also a memory pointer and will
be explored alongside SP in the discussion of the
stack.

29
Flags Register
• The flags register is not meaningful as a unit rather
it is bit wise significant and accordingly each bit is
named separately.
• The bits not named are unused.
• The Intel FLAGS register has its bits organized as
follows

30
If parity flag is set (has a value 1), the result of the operation has an
even number of 1s in it.
31
32
Segment Registers (CS, DS, SS,
ES)
• CS: Code Segment register
• DS: Data segment register
• SS: Stack segment register
• ES: Extra segment register
• These are special registers related to the Intel
segmented memory model and will be discussed
there

33

You might also like