-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperiment.txt
More file actions
768 lines (741 loc) · 17.9 KB
/
Experiment.txt
File metadata and controls
768 lines (741 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
Experiment No: 02
Experiment Name: Taking user input and printing output, printing output
using newline, printing output using space.
Introduction:
Input and output operations allow interaction between the user and the computer system.
In the 8086 microprocessor, keyboard input and screen output are handled through
software interrupts. Proper formatting of output using spaces and newlines improves
readability. This experiment demonstrates how to take user input and display output using
space and newline characters.
Description :
● User input is taken through keyboard using DOS interrupt services.
● Output is displayed using DOS interrupt functions.
● Space character is printed using ASCII value 32.
● Newline is created using Carriage Return 10 and Line Feed 13.
● Registers such as AX,BX, DX, and AH are used for input-output operations.
Taking Input and Printing Output:
Code:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
mov bl,al
mov ah,2
mov dl,bl
int 21h
mov ah,4Ch
int 21h
main endp
end main
Output:
Taking Input and Printing Output with new line:
Code:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
mov bl,al
mov ah,2
mov dl,10
int 21h
mov ah,2
mov dl,13
int 21h
mov ah,2
mov dl,bl
int 21h
mov ah,4Ch
int 21h
main endp
end main
Output:
Taking Input and Printing Output with space:
Code:
.model small
.stack 100h
.code
main proc
mov ah,1
int 21h
mov bl,al
mov ah,2
mov dl,32
int 21h
mov ah,2
mov dl,bl
int 21h
mov ah,4Ch
int 21h
main endp
end main
Output:
Conclusion:
In this experiment, user input was successfully taken and displayed with proper
formatting using space and newline characters. The experiment enhanced understanding
of keyboard input handling, output display, and formatted printing using ASCII control
characters in the 8086 microprocessor.
Experiment No: 03
Experiment Name: Implementing addition, subtraction,
multiplication and division in assembly language
Introduction:
Arithmetic instructions in the 8086 microprocessor allow manipulation of numeric data at the
register and memory level. These operations form the foundation of computational logic in
low-level programming.
The primary arithmetic instructions are:
● ADD → Addition
● SUB → Subtraction
● MUL → Unsigned multiplication
● DIV → Unsigned division
In this experiment, arithmetic operations are performed on 8-bit numbers. The result is displayed
in hexadecimal format using DOS interrupt 21h, following the same printing structure used in
the previous experiment.
Code:
Addition
.model small
.stack 100h
.data
num1 db 14h
num2 db 05h
msg db 'Result = $'
.code
main proc
mov ax, @data
mov ds,ax
; Print message
mov dx, offset msg
mov ah, 09
int 21h
; ---------------- ADDITION ----------------
mov al, num1
add al, num2
mov bl, al
; -------- PRINT HIGH NIBBLE --------
mov al, bl
shr al,4
call print_hex
; -------- PRINT LOW NIBBLE --------
mov al, bl
and al, 0Fh
call print_hex
; EXIT
mov ah, 4Ch
int 21h
main endp
;-------------------------------------------
; PRINTS hex digit in AL (0–15)
;-------------------------------------------
print_hex proc
add al, 48
cmp al, 57
jbe out
add al, 7
out:
mov dl, al
mov ah, 02h
int 21h
ret
print_hex endp
end main
Output:
Substraction
; ---------------- SUBTRACTION ----------------
mov al, num1
sub al, num2
mov bl, al
Output:
Multiplication
; ---------------- MULTIPLICATION ----------------
mov al, num1
mov ah, 00h
mov cl, num2
mul cl ; AX = AL × CL
mov bl, al ; lower byte
Output:
Division
; ---------------- DIVISION ----------------
mov ax, 0000h
mov al, num1
mov cl, num2
div cl ; AL = quotient, AH = remainder
mov bl, al
Output:
Explanation of Output:
Given:
num1 = 14h
num2 = 05h
Addition:
14h + 05h = 19h
Output:
Result = 19
Operation Calculation (Hex) Result
Addition 14h + 05h 19h
Subtraction 14h – 05h 0Fh
Multiplication 14h × 05h 64h
Division 14h ÷ 05h 04h
Conclusion:
This experiment demonstrates arithmetic operations using 8086 assembly
language instructions. The ADD, SUB, MUL, and DIV instructions enable basic
numeric computation at the hardware level.
Key Observations:
● ADD and SUB directly modify the destination register.
● MUL stores the result in AX (AL × operand).
● DIV stores quotient in AL and remainder in AH.
● Proper register preparation is essential before multiplication and division.
Understanding arithmetic instructions is fundamental for low-level programming,
embedded systems, operating systems development, and performance-critical
applications.
Experiment No: 04
Experiment Name: Implementing Logical (AND, OR, NOT), Shift
(Left, Right) and Rotate Operations in 8086 Assembly Language
Introduction:
Logical, shift, and rotate instructions are fundamental bitwise operations in the 8086
microprocessor. These instructions manipulate data at the bit level and are widely used in
low-level programming, cryptography, embedded systems, and performance-critical
routines.
● Logical Operations
○ AND → Performs bitwise conjunction.
○ OR → Performs bitwise disjunction.
○ NOT → Performs bitwise complement.
● Shift Operations
○ SHL (Shift Left) → Multiplies by 2 for each shift.
○ SHR (Shift Right) → Divides by 2 for each shift (unsigned).
● Rotate Operations
○ ROL (Rotate Left) → Rotates bits left without loss.
○ ROR (Rotate Right) → Rotates bits right without loss.
In this experiment, logical AND operation is implemented on an 8-bit number. The result
is displayed in hexadecimal format using DOS interrupt 21h.
Code:
AND
.model small
.stack 100h
.data
num db 017h
msg db 'Result = $'
.code
main proc
mov ax, @data
mov ds,ax
;Print message
mov dx, offset msg
mov ah, 09
int 21h
;AND operation
mov al, num
and al, 01h
mov bl, al
; ----------------PRINT HIGH Nibble------------------
mov al, bl
shr al,4
call print_hex
;-----------------PRINT LOW Nibble-------------------
mov al, bl
and al, 0Fh
call print_hex
;EXIT
mov ah, 4Ch
int 21h
main endp
;-------------------------------------------
; PRINTS hex digit in al (0u15)
;-------------------------------------------
print_hex proc
add al, 48
cmp al, 57
jbe out
add al, 7
out:
mov dl, al
mov ah, 02h
int 21h
ret
print_hex endp
end main
Output:
OR
;OR operation
mov al, num
or al, 01h
mov bl, al
Output:
NOT
;NOT operation
mov al, num
not al
mov bl, al
Output:
Shift Right
; SHR operation
mov al, num
shr al, 1
mov bl, al
Output:
Shift Left
; SHL operation
mov al, num
shl al, 1
mov bl, al
Output:
Rotate Left
; SHR operation
mov al, num
rol al, 1
mov bl, al
Output:
Rotate Right
; SHR operation
mov al, num
ror al, 1
mov bl, al
Output:
Explanation of Output:
Explanation of Output:
● AND
Initial value: num = 17h
AND with: 01h
17h Binary: 0001 0111
1h Binary: 0000 0001
-----------------------------
AND 0000 0001
● OR
Initial value: num = 17h
OR with: 01h
17h Binary: 0001 0111
1h Binary: 0000 0001
-----------------------------
OR 0001 0111
● NOT
Initial value: num = 17h
17h Binary: 0001 0111
-----------------------------
NOT 1110 1000
● SHIFT LEFT (SHL 1)
Initial value: num = 17h
17h Binary: 0001 0111
-----------------------------
SHL 0010 1110
● SHIFT RIGHT (SHR 1)
Initial value: num = 17h
17h Binary: 0001 0111
-----------------------------
SHR 0000 1011
● ROTATE LEFT (ROL 1)
Initial value: num = 17h
17h Binary: 0001 0111
-----------------------------
ROL 0010 1110
● ROTATE RIGHT (ROR 1)
Initial value: num = 17h
17h Binary: 0001 0111
-----------------------------
ROR 1000 1011
The program prints the result in hexadecimal format using nibble separation (high nibble
and low nibble).
Conclusion:
This experiment demonstrates how logical operations such as AND can be implemented
using 8086 assembly language. The bitwise AND operation isolates specific bits of a
number. Additionally, shift (SHL, SHR) and rotate (ROL, ROR) instructions are essential
for bit manipulation, arithmetic optimizations, and low-level system programming.
Understanding these instructions strengthens knowledge of:
● Bit-level data manipulation
● Flag behavior in 8086
● Efficient arithmetic transformations
● Foundations of cryptographic and embedded system logic
Hence, logical, shift, and rotate instructions are crucial tools in assembly-level
programming and hardware-near computation.
Experiment No: 05
Experiment Name: Assembly Language Programming –
Addition of n numbers using loop.
Introduction:
Looping and indexed addressing are essential concepts in assembly language programming.
The 8086 microprocessor provides the LOOP instruction, which automatically decrements the CX
register and continues execution until CX = 0.
In this experiment:
● An array of 10 word-sized integers is stored in memory.
● The program calculates the total sum using indexed addressing (SI register).
● The LOOP instruction is used to iterate through the array.
● The final sum is converted into decimal digits and displayed using DOS interrupt 21h.
This experiment demonstrates:
● Use of CX as loop counter
● Indexed memory access using SI
● Arithmetic accumulation
● Basic decimal output conversion
Code:
.model small
.stack 100h
.data
n dw 10
number dw 1,2,3,4,5,6,7,8,9,10
sum dw 0
.code
main proc
mov ax, @data
mov ds, ax
mov cx, n ; initializing count register
lea si, number ; load address of array
xor ax, ax ; clear AX (sum accumulator)
; loop
start_loop:
add ax, [si] ; add current array element
add si, 2 ; move to next word (2 bytes)
loop start_loop
mov sum, ax ; store total sum
mov bx, 10
xor dx, dx
div bx ; AX ÷ 10 (AL = tens, DX = remainder)
mov cx, dx ; store remainder (units digit)
; print tens value
add al, '0'
mov dl, al
mov ah, 02h
int 21h
; print units value
add cl, '0'
mov dl, cl
mov ah, 02h
int 21h
main endp
end main
Output:
Explanation:
Step 1: Array Elements
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
Step 2: Summation
Total Sum = 55
Step 3: Division for Decimal Output
The sum (55) is divided by 10:
55 ÷ 10
Quotient = 5
Remainder = 5
● Quotient → Tens digit
● Remainder → Units digit
ASCII conversion is done by adding '0' before printing.
Conclusion:
This experiment successfully demonstrates how to:
● Use the LOOP instruction for controlled iteration.
● Access array elements using indexed addressing (SI).
● Accumulate values using the accumulator register (AX).
● Convert binary values to decimal digits for display.
The program correctly calculates the sum of the first 10 natural numbers and outputs 55.
This experiment strengthens understanding of:
● Memory addressing modes
● Loop control using CX
● Arithmetic processing in registers
● Basic number-to-ASCII conversion techniques
Such techniques are fundamental in system-level programming and embedded software
development.
Experiment No: 06
Experiment Name: Take 2 inputs and print if they are greater
than, less than or equal
Introduction:
Decision-making is an important concept in programming where a program must
choose different actions based on conditions. In the 8086 microprocessor, comparison
between two values is performed using the CMP instruction, which subtracts one
operand from another without storing the result but updates the status flags.
After comparison, conditional jump instructions such as JG (Jump if Greater), JL
(Jump if Less), and JE (Jump if Equal) are used to determine the relationship
between the two numbers. These instructions check the processor flags and transfer
program control accordingly.
In this experiment, two numbers are taken as input and compared. The program then
prints whether the first number is greater than, less than, or equal to the second
number using DOS interrupt services.
Code:
;01.03.2026
.model small
.stack 100h
.data
msg1 db "Enter First Number A: $"
msg2 db "Enter Second Number B: $"
agreater db "A is greater than B $"
bgreater db "B is greater than A $"
abequal db "A is equal to B $"
.code
main proc
mov ax, @data
mov ds, ax
;print first message
mov ah, 09h
lea dx, msg1
int 21h
;Take First Input
mov ah, 1
int 21h
mov bl, al
;print Carriage Return
mov ah, 02h
mov dl, 0Dh
int 21h
;print New Line
mov ah, 02h
mov dl, 0Ah
int 21h
;print Second message
mov ah, 09h
lea dx, msg2
int 21h
;Take Second Input
mov ah, 1
int 21h
mov cl, al
;print Carriage Return
mov ah, 02h
mov dl, 0Dh
int 21h
;print New Line
mov ah, 02h
mov dl, 0Ah
int 21h
;Compare bl and cl
cmp bl, cl
ja acheck
jb bcheck
jmp equal
acheck:
mov ah, 09h
lea dx, agreater
int 21h
jmp exit
bcheck:
mov ah, 09h
lea dx, bgreater
int 21h
jmp exit
equal:
mov ah, 09h
lea dx, abequal
int 21h
jmp exit
exit:
mov ah, 4ch
mov al, 00
int 21h
main endp
end main
Output:
Example 1
Input:
First number = 5
Second number = 3
Comparison: 5 > 3
Output:
Example 2
Input:
First number = 2
Second number = 7
Comparison: 2 < 7
Output:
Example 3
Input:
First number = 4
Second number = 4
Comparison: 4 = 4
Output:
Conclusion:
This experiment demonstrates how two numbers can be compared in 8086 assembly
language using the CMP instruction and conditional jumps. The program successfully
determines whether one value is greater than, less than, or equal to another. This
concept is fundamental for implementing decision-making logic, conditional branching,
and control flow in assembly-level programming.
Experiment No: 07
Experiment Name: Find the smallest among 3 numbers
Introduction:
In programming, comparing multiple values is a common task used to determine the
minimum or maximum value among them. In the 8086 microprocessor, comparison
operations are performed using the CMP instruction, which updates the processor flags
based on the result. Using these flags, conditional jump instructions such as JL (Jump if
Less) or JG (Jump if Greater) can direct the program flow to the appropriate section.
In this experiment, three numbers A, B, and C are taken as input from the user. The
program compares these values step by step and determines which number is the
smallest. Conditional jumps are used after each comparison to identify the minimum
value and display the result.
Code:
.model small
.stack 100h
.data
msg1 db "Enter the value of A = $"
msg2 db "Enter the value of B = $"
msg3 db "Enter the value of C = $"
small db "The smallest number is = $"
.code
main proc
mov ax, @data
mov ds, ax
;print first message
mov ah, 09h
lea dx, msg1
int 21h
;Take First Input
mov ah, 1
int 21h
mov bl, al
;print Carriage Return
mov ah, 02h
mov dl, 0Dh
int 21h
;print New Line
mov ah, 02h
mov dl, 0Ah
int 21h
;print Second message
mov ah, 09h
lea dx, msg2
int 21h
;Take Second Input
mov ah, 1
int 21h
mov cl, al
;print Carriage Return
mov ah, 02h
mov dl, 0Dh
int 21h
;print New Line
mov ah, 02h
mov dl, 0Ah
int 21h
;print Third message
mov ah, 09h
lea dx, msg3
int 21h
;Take Third Input
mov ah, 1
int 21h
mov bh, al
;print Carriage Return
mov ah, 02h
mov dl, 0Dh
int 21h
;print New Line
mov ah, 02h
mov dl, 0Ah
int 21h
;Compare A and B
mov al, bl
cmp al, cl
jle checkA
;B < A
mov al, cl
cmp al, bh
jle showB
jmp showC
checkA:
cmp al, bh
jle showA
jmp showC
showA:
mov ah, 09h
lea dx, small
int 21h
mov ah, 02h
mov dl, bl
int 21h
jmp exit
showB:
mov ah, 09h
lea dx, small
int 21h
mov ah, 02h
mov dl, cl
int 21h
jmp exit
showC:
mov ah, 09h
lea dx, small
int 21h
mov ah, 02h
mov dl, bh
int 21h
exit:
mov ah, 4ch
mov al, 00
int 21h
main endp
end main
Output:
Output Generation:
The program first takes three inputs from the user and stores them in registers. It then
compares A with B using the CMP instruction. The smaller value is then compared with
C. Based on the results of these comparisons and the processor flags, conditional jump
instructions direct the program to display the smallest number.
Conclusion:
This experiment demonstrates how multiple comparisons and conditional jumps can be
used in the 8086 microprocessor to determine the smallest value among several inputs.
It helps in understanding decision-making logic and the use of comparison instructions
in assembly language programming.
Experiment No: 08
Experiment Name: Conversion of capital letter to small
letter and vise-versa.
Introduction:
In programming, character manipulation is essential when working with text data. In the
8086 microprocessor, characters are represented using ASCII codes. The difference
between uppercase and lowercase English letters is 32 in decimal.
For example, the ASCII value of 'A' becomes 'a' by adding 32, and 'a' becomes 'A' by
subtracting 32.
In this experiment, a character is taken as input from the user. The program checks
whether the character is uppercase or lowercase using comparison instructions. If it is
uppercase, 32 is added to convert it into lowercase. If it is lowercase, 32 is subtracted to
convert it into uppercase. Conditional jump instructions are used to control the flow and
display the converted result.
Code:
.model small
.stack 100h
.data
text db 'Input a letter: $'
output db 0Dh,0Ah,'After conversion: $'
.code
main proc
mov ax, @data
mov ds, ax
mov ah, 09h
lea dx, text
int 21h
; input
mov ah, 01h
int 21h
mov cl, al
; uppercase check
cmp cl, 'A'
jl lower_check
cmp cl, 'Z'
jg lower_check
; convert to lowercase
add cl, 32
jmp show_result
lower_check:
; lowercase check
cmp cl, 'a'
jl show_result
cmp cl, 'z'
jg show_result
; convert to uppercase
sub cl, 32
show_result:
; output text
mov ah, 09h
lea dx, output
int 21h
; print character
mov dl, cl
mov ah, 02h
int 21h
mov ah, 4Ch
mov al, 00
int 21h
main endp
end main
Output:
Output Generation:
The program first prompts the user to enter a character and stores it in a register. It then
checks whether the character lies within the ASCII range of uppercase letters ('A'–'Z'). If
true, it adds 32 to convert it to lowercase.
If the character is not uppercase, the program checks whether it lies within the range of
lowercase letters ('a'–'z'). If true, it subtracts 32 to convert it to uppercase.
If the input character does not fall into either category, it remains unchanged. Finally, the
converted character is displayed using DOS interrupt services.
Conclusion:
This experiment demonstrates how ASCII values can be used for character
manipulation in the 8086 microprocessor. It shows the use of comparison instructions
and conditional jumps to determine character type and perform appropriate conversion.
This concept is fundamental in text processing and low-level programming.