0% found this document useful (0 votes)
42 views14 pages

LAB-3 Assembling, Linking and Running

The document discusses assembling, linking, and running programs in MASM and NASM assemblers. It explains the assemble-link-execute cycle and describes listing and map files. It also provides examples of programs written in MASM and NASM that add numbers, demonstrating how to declare variables, perform arithmetic operations, and return control to DOS.

Uploaded by

saleemronline
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views14 pages

LAB-3 Assembling, Linking and Running

The document discusses assembling, linking, and running programs in MASM and NASM assemblers. It explains the assemble-link-execute cycle and describes listing and map files. It also provides examples of programs written in MASM and NASM that add numbers, demonstrating how to declare variables, perform arithmetic operations, and return control to DOS.

Uploaded by

saleemronline
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

LAB-3

Assembling, Linking and


Running
Assembling, Linking, and Running Programs

 Assemble-Link-Execute Cycle
 Listing File
 Map File
Assemble-Link Execute Cycle
 The following diagram describes the steps from creating a
source program through executing the compiled program.
 If the source code is modified, Steps 2 through 4 must be
repeated.
Assemble in MASM
 Executes ML.EXE (the Microsoft Assembler) to
assemble your programs
 Linkxxx.exe(Microsoft Linker)
 Command-Line syntax:
Ml progName.asm ENTER
(progName includes the .asm extension and is written in
notepad usually)

(use make16.bat to assemble and link Real-mode programs)


Listing File
 Use it to see how your program is compiled
 Contains
 source code
 addresses
 object code (machine language)
 segment names
 symbols (variables, procedures, and constants)
Map File
 Information about each program segment:
 starting address
 ending address
 size
 segment type
Assemble in NASM
 You have to give the following command to
assemble with NASM:
 nasm progName.asm –o progName.com –l
progName.lst
 NASM is used to create small programs (.COM
files that are also executables like .EXE files)
 Once we get .com file, we can directly run it or
debug it two ways
 Using Debug progName.com

 Using AFD progName.com


Assemble in NASM
 You have to give the following command to
assemble with NASM:
 nasm progName.asm –o progName.com –l
progName.lst
 NASM is used to create small programs (.COM
files that are also executables like .EXE files)
 Once we get .com file, we can directly run it or
debug it two ways
 Using Debug progName.com

 Using AFD progName.com


Program 1 (.com files)
 Write a program in NASM to add three hex
numbers 5,10,15:
[ORG 0x100]
mov ax,5
mov bx,10
add ax,bx Actual Coding
mov bx,15
add ax, bx
mov ax, 0x4c00
int 0x21
Program 1 (.com files)
 Write a program in MASM to add three hex
numbers 5,10,15:
CODE SEGMENT
ASSUME CS : CODE , DS : CODE , SS : CODE
ORG 100H
ENTRY: JMP L1
; data definitions come here

L1:
mov ax,5H
mov bx,10H
add ax,bx
mov bx,15H
add ax, bx
; Return to DOS
MOV AX , 4C00H
INT 21H
CODE ENDS
END ENTRY
Program 1(.Exe files)
 Write a program in MASM to add three hex
numbers 5,10,15:
.MODEL SMALL
.STACK 64
.DATA
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV AX,05H
MOV BX,10H
ADD AX,BX Program Code
MOV BX,15H
ADD AX,BX
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Program 1 (.com files)
 Write a program in NASM to add two
numbers Num1 and Num2 and store the
result in Sum
[ORG 0x100]
mov ax,Num1
mov bx,Num2
add ax,bx Actual Coding
mov Sum,ax
mov ax, 0x4c00
int 0x21
Num1 DW 5
Num2 DW 15 Variables Declarations
Sum DW 0
Program 1 (.exe files)
 Write a program in MASM to add three
numbers num1, num2, and num3 and store
the result in Sum
.MODEL SMALL
.STACK 32
.DATA
num1 DW 5
num2 DW 10
num3 DW 15
sum DW 0

.CODE
MAIN:
MOV AX, @DATA
MOV DS, AX
mov ax, num1 ; value at num1
mov bx, num2
add ax,bx
mov bx, num3
add ax,bx
mov sum,ax ;location num1
; RETURN TO DOS
MOV AX, 4C00H
INT 21H
END MAIN
Program 1 (.exe files)
 Write a program in MASM to add three
numbers num1, num2, and num3 and store
the result in Sum—See if it works OK?
.MODEL SMALL
.STACK 32
.DATA
num1 DW 5
DW 10
DW 15
DW 0

.CODE
MAIN:
MOV AX, @DATA
MOV DS, AX
mov ax, num1 ; value at num1,
mov bx, [num1+2] ;
add ax,bx
mov bx, [num1+4]
add ax,bx
mov [num1+6],ax
; RETURN TO DOS
MOV AX, 4C00H
INT 21H
END MAIN

You might also like