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

Examples of Programs

The document contains 7 questions that provide assembly language code examples for common operations on data stored in memory locations. The examples demonstrate how to: add two 16-bit numbers and store the result; add a series of bytes stored from a memory range and store the result; transfer a block of bytes between two memory ranges; multiply two 16-bit numbers and store the 32-bit result; find the highest number in a series and store it; count the negative numbers in a series and store the result; and sort a series of numbers in ascending order.

Uploaded by

Rohit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Examples of Programs

The document contains 7 questions that provide assembly language code examples for common operations on data stored in memory locations. The examples demonstrate how to: add two 16-bit numbers and store the result; add a series of bytes stored from a memory range and store the result; transfer a block of bytes between two memory ranges; multiply two 16-bit numbers and store the 32-bit result; find the highest number in a series and store it; count the negative numbers in a series and store the result; and sort a series of numbers in ascending order.

Uploaded by

Rohit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Example Programs

Q 1) WAP to ADD two 16 bit numbers.


Operands and the result should be in the data segment.

Data SEGMENT // Starts a segment by the name Data


A DW 1234H // Declares A as 16-bits with value 1234H
B DW 5140H // Declares B as 16-bits with value 5140H
Sum DW ? // Declares Result as a 16-bit word
Carry DB 00H // Declare carry as an 8-bit variable with a value 0
Data ENDS

Code SEGMENT

ASSUME CS: Code, DS: Data // Informs the assembler about the correct segments

MOV AX, Data // Puts segment address of Data into AX


MOV DS, AX // Transfers segment address of Data from AX to DS

MOV AX, A // Gets the value of A into AX


ADD AX, B // Adds the value of B into AX
JNC Skip // If no carry then directly store the result
MOV Carry, 01H // If carry produced then make variable “Carry=1”
Skip: MOV Sum, AX // Store the sum in the variable “Sum”

INT3 // Optional Breakpoint

Code ENDS

END
Q 2) WAP to add a series of 10 bytes stored in the memory from locations 20,000H to
20,009H. Store the result immediately after the series.

Code SEGMENT

ASSUME CS: Code

MOV AX, 2000H


MOV DS, AX

MOV SI, 0000H


MOV CX, OOOAH
MOV AX, 0000H
Back: ADD AL, [SI]
JNC Skip
INC AH
Skip: INC SI

LOOP Back
MOV [SI], AX

INT3

Code ENDS

END
Q 3) WAP to transfer a block of 10 bytes from location 20,000H to 30,000H.

Code SEGMENT

ASSUME CS: Code

MOV AX, 2000H


MOV DS, AX
MOV AX, 3000H
MOV ES, AX
MOV SI, 0000H
MOV DI, 0000H
MOV CX, 000AH
CLD
REP MOVSB

INT3

Code ENDS

END
Q 4) WAP to multiply two 16-bit numbers. Operands and result in Data Segment.

Data SEGMENT

A DW 1234H
B DW 1845H
Result DD ?

Data ENDS

Code SEGMENT
ASSUME CS: Code, DS: Data
MOV AX, Data
MOV DS, AX

MOV AX, A
MUL B
LEA BX, Result
MOV [BX], AX
MOV [BX+2], DX

INT3

Code ENDS

END
Q 5) WAP to find “highest” in a given series of 10 numbers beginning from location
20,000H. Store the result immediately after the series.

Code SEGMENT

ASSUME CS: Code


MOV AX, 2000H
MOV DS, AX

MOV SI, 0000H


MOV CX, 000AH
MOV AL, 00H
Back: CMP AL, [SI]
JNC Skip
MOV AL, [SI]
Skip: INC SI

LOOP Back
MOV [SI], AL

INT3

Code ENDS

END
Q 6) WAP to find the number of –ve numbers in a series of 10 numbers from 20,000H. Store
the result immediately after the series.

Code SEGMENT

ASSUME CS: Code


MOV AX, 2000H
MOV DS, AX

MOV SI, 0000H


MOV CX, 000AH
MOV AH, 00H
Back: MOV AL, [SI]
RCL AL, 01H
JNC Skip
INC AH
Skip: INC SI

LOOP Back
MOV [SI], AH

INT3

Code ENDS

END
Q 7) WAP to SORT a series of 10 numbers from 20,000H in ascending order.

Code SEGMENT

ASSUME CS: Code


MOV AX, 2000H
MOV DS, AX

MOV CH, 09H


Bck2: MOV SI, 0000H
MOV CL, 09H
Bck1: MOV AX, [SI]
CMP AH, AL
JNC Skip
XCHG AL, AH
MOV [SI], AX
Skip: INC SI
DEC CL
JNZ Bck1
DEC CH
JNZ Bck2

INT3

Code ENDS

END

You might also like