Micro Ass2
Micro Ass2
Write and run a program that transfers 6 bytes of data from memory locations with offset
of 0010H to memory locations with offset of 0028H.
Step-by-Step Guide:
1. Initialize the Data Segment:
Point the DS register to the data segment containing the source data at offset
0010H.
2. Initialize the Extra Segment:
Similarly, point the ES register to the data locations for the destination at offset
0028H.
3. Set Up Source and Destination Pointers:
Use SI (Source Index) for the source data address and DI (Destination Index) for
the destination data address.
4. Copy 6 Bytes of Data:
Use a loop to copy each byte from the source to the destination.
Increment SI and DI to move through the data.
5. Terminate the Program:
Call DOS interrupt for program termination.
Here's the assembly code to accomplish this:
.model small
.stack 100h
.data
; Example data might be loaded here for the program;
; assume that the data is already present in memory at offset 0010H.
source db 6 dup(?) ; Example source bytes initialized by user's need
.code
main proc
mov ax, @data ; Load data segment address into AX
mov ds, ax ; Initialize DS with AX
mov es, ax ; Initialize ES with same segment as DS
transfer_loop:
mov al, ds:$$ si $$ ; Load byte from source to AL
mov es:$$ di $$, al ; Store byte from AL to destination
inc si ; Increment source index
inc di ; Increment destination index
loop transfer_loop ; Repeat until CX is zero
; Terminate program
mov ah, 4Ch ; DOS function 4Ch - Terminate
int 21h
main endp
end main
Explanation:
Registers and Directives:
.model small, .stack 100h: Set up a small memory model with stack space.
mov ax, @data; mov ds, ax: Load the data segment.
es: ax: Point both DS and ES to the same data segment for ease.
Main Code Logic:
Initialization: si and di are initialized to the starting offsets of the source and
destination memory locations, respectively.
Loop: The transfer_loop moves each byte from $$ ds:si $$ to $$ es:di $$.
The loop instruction decrements cx and continues the loop until cx becomes
zero.
Program Termination: Use int 21h with ah = 4Ch to end the program.
Ensure to have an environment that allows the execution of 16-bit assembly
code, such as DOSBox, or use an emulator that supports 8086 assembly
instructions since modern systems usually do not execute 16-bit code natively.
Let me know if you have any more questions or need further clarifications!
6. Write an ALP that Add two numbers N1 and N2. If the result is positive, save at
POSITIVE memory location. If the result is negative, save at NEGATIVE memory location.
Otherwise, save at ZERO.
Step-by-Step Guide:
1. Set Up the Data Segment:
Define memory locations for N1N1, N2N2, and to store the results
at POSITIVE, NEGATIVE, and ZERO.
2. Load Numbers into Registers:
Use registers like AL and BL to hold values N1N1 and N2N2.
3. Perform the Addition:
Add N1N1 and N2N2 with the ADD instruction.
4. Check the Result:
Use conditional jumps to check the sign of the result after addition.
5. Store the Result:
Depending on the sign, store the result in the appropriate memory location.
Assembly Code:
.model small
.stack 100h
.data
N1 db 5 ; Example value for N1
N2 db -10 ; Example value for N2
POSITIVE db ? ; Reserved for positive result
NEGATIVE db ? ; Reserved for negative result
ZERO db ? ; Reserved for zero result
.code
main proc
mov ax, @data ; Initialize data segment
mov ds, ax
positive_case:
mov POSITIVE, al ; Store result at POSITIVE location
jmp end_program ; Jump to end
negative_case:
mov NEGATIVE, al ; Store result at NEGATIVE location
jmp end_program ; Jump to end
zero_case:
mov ZERO, al ; Store result at ZERO location
end_program:
mov ah, 4Ch ; End the program
int 21h
main endp
end main
Explanation:
Data Declaration:
N1 and N2 are initialized with example values for demonstration.
POSITIVE, NEGATIVE, and ZERO are declared uninitialized, as they will hold the
result.
Program Logic:
Initialize the data segment with mov ax, @data; mov ds, ax.
Load N1N1 and add N2N2 to AL.
Use jz to check if the result is zero and js to check if it's negative.
Store the result in the corresponding memory location based on the condition.
Program Termination:
Use int 21h with ah = 4Ch for DOS termination.
This example assumes you are using an environment where you can test and
run 8086 assembly language programs, such as DOSBox. Adjust N1 and N2 as
necessary for different test cases. Let me know if you need further assistance or
have additional questions!
8. Using string instructions, write an 8086-assembly language program that
transfers a block byte
Assembly Code:
.model small
.stack 100h
.data
DATA1 db 'DEPARTMENT OF COMPUTER SCIENCE!', 0 ; Source string with null
terminator
DATA2 db 30 dup('$') ; Destination buffer sized to
accommodate DATA1
.code
main proc
mov ax, @data ; Initialize data segment
mov ds, ax
mov es, ax ; Same segment used for both source and destination
; Terminate program
mov ah, 4Ch ; DOS function 4Ch - Terminate
int 21h
main endp
end main
Explanation:
Data Segment:
DATA1 initializes with the given string and includes a null terminator (represented
by a 0) to mark the end.
DATA2 is declared with sufficient space to hold the content of DATA1.
Logic Implementation:
Initializing DS and ES ensures both source and destination are within the same
data segment.
Setting up SI for the source and DI for the destination prepares the registers for
the operation.
CX contains the number of bytes to move, in this case, the length of the string
plus one for the null terminator.
CLD clears the direction flag, which means the copy operation moves forward in
memory.
REP MOVSB performs the repetitive byte-wise move from the source to the
destination.
Termination:
Use int 21h with ah = 4Ch to exit gracefully.
This code assumes you are running it in an environment that supports 16-bit
8086 assembly language, like DOSBox. Make sure to tailor the string length if
the string size changes. Let me know if there's anything else or if you have
questions on various parts of the code!
• USART interfacing
11. Write an 8086-assembly language program that display all decimal digits Repeat for
all capital letters Repeat for all small letters
Step-by-Step Guide:
1. Set up the Data Segment:
Reserve space for storing values like the ASCII digits and letters if needed.
2. Initialize Registers:
Use registers to iterate through the ASCII values.
Keep DX register, which generally holds the character to be displayed.
3. Display Decimal Digits (0-9):
Iterate from ASCII 48 ('0') to 57 ('9') using a loop.
Use DOS interrupt 21h, function 02h to display each character.
4. Display Capital Letters (A-Z):
Iterate from ASCII 65 ('A') to 90 ('Z') using a loop.
Use the same output function to display each character.
5. Display Small Letters (a-z):
Iterate from ASCII 97 ('a') to 122 ('z') using a loop.
Again, use the output function to display each character.
6. Terminate the Program:
Use DOS interrupt 21h, function 4Ch to terminate the program.
; Terminate program
mov ah, 4Ch ; DOS function to terminate program
int 21h
main endp
end main
Explanation:
Model and Stack: The .model small and .stack directives set up a small
memory model (suitable for .COM programs) and allocate space for the
stack.
Data Segment: Currently not used, but defined if future data residency is
needed.
Code Segment:
Start by setting up data segment using mov ax, @data and mov ds, ax.
Each section for digits, capital letters, and small letters uses a loop to go
through their respective ASCII ranges.
int 21h with ah = 02h is used to output each character stored in dl.
USART Interfacing
Overview of USART Interfacing
1. USART Basics:
Universal: Can handle both synchronous (clock required) and asynchronous (no
clock required) data transmission.
Serial Communication: Data is sent one bit at a time, as opposed to parallel
communication, where multiple bits are sent simultaneously.
2. Key Components for Interfacing:
USART device (like 8251A).
Baud rate generator for setting communication speed.
Data and control registers for managing the flow of data.
Peripheral interface pins to connect the USART device to the 8086
microprocessor.
3. Interfacing Steps:
Connection: Connect USART data, control, and status pins appropriately to the
8086 bus.
Initialization: Set up the USART with the appropriate control words to define
operational mode, baud rate, data bits, stop bits, and parity.
Data Transmission: Write data to the USART's data register to send data.
Data Reception: Read data from the USART's data register when receiving.
; Transmit Data
wait_for_ready:
in al, STATUS_PORT ; Read USART status register
test al, 01h ; Test for transmitter ready
jz wait_for_ready ; Loop until ready
; Receive Data
wait_for_data:
in al, STATUS_PORT ; Read USART status register
test al, 02h ; Test for receive data availability
jz wait_for_data ; Loop until data received
Explanation:
Control Word: Configure USART communication settings like baud rate and
parity.
Status Register Polling: Continuously check ready status before transmitting
and receiving data.
Data Register: Transmit and receive data using buffer registers.
The specifics will differ based on the USART chip and the connections used in
practice. Check the relevant datasheets and hardware manuals for exact details
on control words and signal connections.
Let me know if you have any specific questions about USART interfacing or need
more detailed instructions!
Clear