Document Details

Uploaded by Deleted User

Tags

8086 assembly language assembly programming computer organization programming

Summary

This document contains 10 experiments on 8086 Assembly Language Programming, covering various topics like register operations, arithmetic operations, string operations, memory access, etc.

Full Transcript

## EXPERIMENT-1 4770 ← HOOP0:0001 Write down the result stored in the affected registers and the status of affected flags after each instruction executes. | No. | Instruction | CS | AX | BX | CX | DX | Flag Register | |---|---|---|---|---|---|---|---| | 00 | | 0100 | 0000 | 00 00 | 00 00 | 00 00...

## EXPERIMENT-1 4770 ← HOOP0:0001 Write down the result stored in the affected registers and the status of affected flags after each instruction executes. | No. | Instruction | CS | AX | BX | CX | DX | Flag Register | |---|---|---|---|---|---|---|---| | 00 | | 0100 | 0000 | 00 00 | 00 00 | 00 00 | AH AL-GH BL CHICL DHDL OF SFZRAFP PRICE | | 01 | MOV AX, 2345H | 0100 | 0003 | 23 45 | 00 00 | 00 00 | 00 00 00 00 00 0 0 0 0 0 0 0 0 0 | | 02 | MOV BX, 6789H | 0100 | 0006 | 23 45 | 67 89 | 00 00 | 00 00 00 00 00 0 0 0 0 0 0 0 0 0 | | 03 | ADD AX, BX | 0100 | 0008 | 8A CE | 67 89 | 00 00 | 00 00 1 1 0 0 0 0 0 0 0 0 0 0 0 | | 04 | SUB AX, BX | 0100 | 000A | 23 45 | 67 89 | 00 00 | 00 00 1 1 0 0 0 0 0 0 0 0 0 0 0 | | 05 | MOV CL, 02H | 0100 | 000C | 23 45 | 67 89 | 00 02 | 00 00 | 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 06 | MOV AL, 0AH | 0100 | 000E | 23 45 | 67 89 | 00 02 | 00 00 | 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 07 | MUL CL | 0100 | 0010 | 23 OA | 67 89 | 00 02 | 00 00 | 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 08 | DIV CL | 0100 | 0012 | 00 14 | 67 89 | 00 02 | 00 00 | 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 09 | INC AL | 0100 | 0014 | 00 08 | 67 89 | 00 02 | 00 00 | 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 10 | DEC CL | 0100 | 0016 | 00 08 | 67 89 | 00 01 | 00 00 | 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 11 | MOV AL, 35H | 0100 | 0018 | 00 35 | 67 89 | 00 01 | 00 00 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 12 | AND AL, OFH | 0100 | 001A | 00 05 | 67 89 | 00 01 | 00 00 | 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 | | 13 | OR AL, 30H | 0100 | 0010 | 00 35 | 67 89 | 00 01 | 00 00 | 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 | | 14 | XOR AL, OFFH | 0100 | 001E | 00 CA | 67 89 | 00 01 | 00 00 | 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 | | 15 | NOT AL | 0100 | 0020 | 00 35 | 67 89 | 00 01 | 00 00 | 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 | | 16 | MOV DX, 5678H | 0100 | 0023 | 00 85 | 67 89 | 00 01 | 56 78 | 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 17 | MOV BX, 1234H | 0100 | 0026 | 00 35 | 12 34 | 00 01 | 56 78 | 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 18 | XCHG BX, DX | 0100 | 0028 | 00 35 | 56 78 | 00 01 | 12 34 | 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 19 | MOV AL, 09H | 0100 | 002A | 00 09 | 56 78 | 00 01 | 12 34 | 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 20 | MOV BL, 00H | 0100 | 0020 | 00 09 | 56 78 | 00 01 | 12 34 | 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 21 | STC | 0100 | 0020 | 00 09 | 56 00 | 00 01 | 12 34 | 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 22 | ADC AL, BL | 0100 | 002F | 00 0A | 56 00 | 00 01 | 12 34 | 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 | | 23 | DAA | 0100 | 0030 | 00 10 | 56 00 | 00 01 | 12 34 | 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 | HAAHD0001 ## EXPERIMENT - 2 4770 ← HOOP0:0001 1. Data: - 1000: 0400H → OFFH (15×15+15 = 255) Result: - | Instruction | DS | SI | DX | |---|---|---|---| | MOV DX, 1000H | 0100 | 0000 | 1000 | | MOV DS, DX | 0100 | 0000 | 1000 | | MOV SI, 0400H | 1000 | 0400 | 1000 | | MOV [SI], OFFH | 1000 | 0400 | 1000 | | XOR DX, DX | 1000 | 0400 | 1000 | | MOV DL, [SI] | 1000 | 0400 | 1000 | | HLT | 1000 | 0400 | FF | Final Result: - 1000:0400H → 0FFH 2. Data: - 1000:0400H → 07H 1000:0402H → 04H | Instruction | DS | SI | DI | AX | 1000:0400H | 1000:0402H | |---|---|---|---|---|---|---| | MOV AX, 1000H | 0100 | 00 00 | 00 00 | 1000 | 00 | 00 | | MOV DS, AX | 1000 | 00 00 | 00 00 | 1000 | 00 | 00 | | MOV [0400H], 07H | 1000 | 00 00 | 00 00 | 1000 | 07 | 00 | | MOV [0402H], 04H | 1000 | 00 00 | 00 00 | 1000 | 07 | 04 | | MOV SI, 0400H | 1000 | 0400 | 00 00 | 1000 | 07 | 04 | | MOV DI, 0402H | 1000 | 0400 | 0402 | 1000 | 07 | 04 | | XOR AX, AX | 1000 | 0400 | 0402 | 00 00 | 07 | 04 | | XCHG AX, [SI] | 1000 | 0400 | 0402 | 00 07 | 07 | 04 | | XCHG AX, [DI] | 1000 | 0400 | 0402 | 04 07 | 07 | 04 | | XCHG AX, [SI] | 1000 | 0400 | 0402 | 07 04 | 07 | 04 | | HLT | 1000 | 0400 | 0402 | 07 | 07 | 04 | Final Result: - 1000:0400H → 04H 1000:0402H → 07H ## EXPERIMENT - 3 4770 ← HOOP0:0001 Write 8086 instructions for the following: - 1. Read the value from memory location 1000H: 0400H and store it in register DL. ``` MOV DX, 1000H ; Put address in DX MOV DS, DX ; Move it into data Segment MOV SI, 0400H ; put offset into SI MOV [SI], OFFH ; Putting a value into address. XOR DX, DX ; Clearing DX MOV DL, [SI] ; Loading value from given address into DL HLT ``` 2. Exchange the contents of memory location 1000:0400H and 1000:0402H. ``` MOV AX, 1000H ; Put address in AX MOV DS, AX ; Move it into DS MOV [0400H], 07H; Putting two random values in MOV [0402H], 04H ; In this case: 7, and 4: MOV SI, 0400H ; Loading address offsets MOV DI, 0402H ; Clear AX XOR AX, AX XCHG AX, [SI] XCHG AX, [DI] XCHG AX, [SI] HLT ``` ## EXPERIMENT - 4 4770 ← HOOP0:0010 Write an 8086 Assembly language program to transfer ten numbers from a given array to memory location starting from address 1000H:0100H ``` MOV AX, 1000H ; Load Base Address in AX MOV ES, AX XOR AX, AX MOV [0400H], 00H ; Putting ten values in another location MOV [0401H], 01H MOV [0402H], 02H MOV [0403H], 03H MOV [0404H], 04H MOV [0405H], 05H MOV [0406H], 06H MOV [0407H], 07H MOV [0408H], 08H MOV [0409H], 09H MOV SI, 0400H ; Putting Location of values into SI MOV DI, 0100H ; Putting destination in DI MOV CL, 0AH ; Setting counter to 10. Transfer: MOV AL, [SI] ; Loads values into AL MOV ES:[DI], AL ; Copies them into ES:(1000H):DI(0100H) INC SI ; Increment offsets INC DI LOOP Transfer ; Loop the Transfer until CL=0, which is ten times here. HLT ``` ## EXPERIMENT - 5 4770 ← HOOP0:0010 Write an 8086 assembly language program to obtain count of positive and negative numbers from a given series of ten numbers and store the count respectively in DL and DH. ``` MOV [0400H], 1 ; Putting values in. MOV [0401H], 2 MOV [0402H], 3 MOV [0403H], 4 MOV [0404H], -5 MOV [0405H], 6 MOV [0406H], -7 MOV [0407H], 8 MOV [0408H], -9 MOV [0409H], 10 MOV SI, 0400H ; Set SI to address of 1st value. MOV CL, 0AH ; Set counter to 10. check: JNS posint ; Move current number into AL. MOV AL, [SI] ADD AL, 00H ; Add 00H to AL. This sets SF to 1 for negative values. negint: INC DH ; Increment DH for negative values. JMP next ; Jumpo to "next", so we don't increment DL. posint: INC DL ; Increment DL for positive values. next: INC SI ; Increments SI for next value. LOOP check ; Loops "check" until CX is equal to 0. HLT ``` ## EXPERIMENT - 6 4770 ← HOOP0:0010 Write an 8086 assembly language program to find the largest number from a given series of 10 unsigned numbers stored in memory starting from address 1000:0400H. Store the result in register DL. ``` MOV AX, 1000H ; Store 1000H (base address.) in AX. MOV DS, AX ; Move address into DS. MOV [0400H], 0AH ; Entering values to be assessed. MOV [0401H], 1AH MOV [0402H], 0EH MOV [0403H], 08H MOV [0404H], 20H MOV [0405H], 03H MOV [0406H], 0A0H MOV [0407H], 15H MOV [0408H], 0BFH MOV SI, 0400H ; Moving address of first value into SI. MOV CL, 0AH ; Set counter to 10. XOR AX, AX ; Clear AX. comparison: MOV AL, [SI] ; Move value into AL. CMP DL, AL ; CMP sets CF (Carry flag) to 1 when Al is bigger. JC updateValue ; If CF = 1, jump to "updateValue". next: INC SI ; Increment SI for next value. LOOP comparison ; Loop comparison until CX = 0. HLT updateValue: MOV DL, AL ; Copy current value into DL. JMP next ; Jump to "next" for next value. ``` ## EXPERIMENT - 7 4770 ← HOOP0:0010 Write an 8086 assembly program to find the count of even and odd numbers from a given series of 10 unsigned numbers. Store the count of even numbers in DL and count of odd numbers in DH. ``` MOV [0400H], 01H ; Putting values in. MOV [0401H], 02H MOV [0402H], 00H MOV [0403H], 0AH MOV [0404H], 0BH MOV [0405H], 11H MOV [0406H], 14H MOV [0407H], 06H MOV [0408H], 0DH MOV [0409H], 1CH MOV SI, 0400H ; Set SI to location of first value. MOV CL, 0AH ; Set counter to 10. XOR AX, AX ; Clear AX and DX. XOR DX, DX check: MOV AL, [SI] ; Move current value in AL. AND AL, 01H ; AND is used for masking, as LSB will determine even or odd. JNE odd ; Jump Not Equal? as odd numbers will give 1 for previous step. even: INC DL ; Increment DL for even numbers. INC SI ; Increment SI to get next value. LOOP check ; Loop "check" for other values until CX=0. HLT odd: INC DH ; Increment DH for odd numbers. INC SI ; Increment SI for next value. LOOP check ; Loop check for other values found. HLT ``` ## EXPERIMENT - 8 4770 ← HOOP0:0010 Write an 8086 assembly language program using string instruction to copy string "Hello" from memory location 1000:0600H to 2000:0600H. ``` MOV AX, 1000H ; Move first address into AX. MOV DS, AX ; Move it into DS. MOV [0600H], "H" ; Putting string one character at a time MOV [0601H], "e" ; at source location. MOV [0602H], "l" MOV [0603H], "l" MOV [0604H], "o" MOV AX, 2000H ; Move second (destination) address into AX. MOV ES, AX ; Move it into ES. MOV SI, 0600H ; Set SI to offset to be copied from AX. MOV DI, 0600H ; Set DI to offset of destination (where in ES). MOV CL, 05H ; Set counter to 5. CLD ; Clear direction flag to ensure values copy towards higher addresses REP MOVSB ; REP with repetition that the CX = 0, copying from DS:SI to ES:DI. HLT ``` ## EXPERIMENT - 9 4770 ← HOOP0:0010 Write an 8086 assembly language program to find the smallest number from a given series of 10 unsigned numbers stored in memory starting from address 1000:0400H. Store result in DL. ``` MOV AX, 1000H ; Move base address into AX. MOV DS, AX ; Move it into DS. MOV [0400H], 05H ; Put values in. MOV [0401H], 06H MOV [0402H], 04H MOV [0403H], 17H MOV [0404H], 03H MOV [0405H], 02H MOV [0406H], 00H MOV [0407H], 0DH MOV [0408H], 01H MOV [0409H], 0LH MOV SI, 0400H ; Set SI to offset value. MOV CL, 0AH ; Setting counter to 10. XOR AX, AX ; Clearing AX & DX. XOR DX, DX MOV DL, [SI] ; Move first value into DL. We account for DL=0 at start. comparison: MOV AL, [SI] ; Move current value into AL. CMP AL, DL ; Compare AL:DL and set flag. JC updateValue ; Jump to "updateValue" if carry flag is set. next: INC SI ; Increment SI for next value. LOOP comparison ; Loop comparison until CX is 0. HLT updateValue: MOV DL, AL ; Copy value of AL into DL. JMP next ``` ## EXPERIMENT - 10 4770 ← HOOP0:0010 Write an 8086 assembly language program to find the 2's complement of number stored in memory address 1000:0400H. Store the result in register DL. ``` MOV AX, 1000H ; Move Base address in AX. MOV DS, AX ; Move it into DS. XOR AX, AX ; Clear AX. MOV [0400H], 0CH ; Move a value at given address. MOV AL, [0400H] ; Copy it into AL. NEG AL ; NEG gives 2's complement of AL. MOV DL, AL ; Move value into DL. HLT ```

Use Quizgecko on...
Browser
Browser