Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Important programs of 8086 (Exam point of view)
- 1. Write an ALP to find factorial of number for 8086. MOV AX, 05H
- MOV CX, AX
- Back: DEC CX
- MUL CX
- LOOP back
- ; results stored in AX
- ; to store the result at D000H
- MOV [D000], AX
- HLT
- 2. The 8 data bytes are stored from memory location E000H to E007H. Write 8086 ALP to
- transfer the block of data to new location B001H to B008H. MOV BL, 08H
- MOV CX, E000H
- MOV EX, B001H
- Loop: MOV DL, [CX]
- MOV [EX], DL
- DEC BL
- JNZ loop
- HLT
- 3. Write a program to display string ëElectrical and Electronics Engineeringí for 8086. Title display the string
- Dosseg
- Written by CHANDRA THAPA (October 2012) 2
- .model small
- .stack 100h
- .data
- String1 db ëElectrical and Electronics Engineeringí, $
- .code
- Main proc
- MOV AX, @data
- MOV DS, AX
- MOV AH, 09H
- MOV DX, offset String1
- INT 21H
- MOV AH, 4CH
- INT 21H
- Main endp
- End Main
- 4. Write a program to reverse the given string for 8086. Title reverse the given string
- Dosseg
- .model small
- .stack 100h
- .data
- String1 db ëassembly language programí, $
- Length dw $-String1-1
- .code
- Written by CHANDRA THAPA (October 2012) 3
- Main proc
- MOV AX, @data
- MOV DS, AX
- MOV SI, offset String1
- MOV CX, Length
- ADD SI, CX
- Back: MOV DL, [SI]
- MOV AH, 02H
- INT 21H
- DEC SI
- LOOP Back
- MOV AH, 4CH
- INT 21H
- Main endp
- End Main
- 5. Write a program to multiply 2 numbers (16-bit data) for 8086. Title multiply two numbers
- Written by CHANDRA THAPA (October 2012) 4
- .code
- MULT proc
- MOV AX, @data
- MOV DS, AX
- MOV AX, Multiplicant
- MUL Multiplier
- MOV Product, AX
- MOV Product+2, DX
- MOV AH, 4CH
- INT 21H
- MULT endp
- End MULT
- 6. Sum of series of 10 numbers and store result in memory location total. Title Sum of series
- Dosseg
- .model small
- .stack 100h
- .data
- List db 12,34,56,78,98,01,13,78,18,36
- Total dw ?
- .code
- Main proc
- MOV AX, @data
- MOV DS, AX
- MOV AX, 0000H
- Written by CHANDRA THAPA (October 2012) 5
- MOV CX, 0AH ; counter
- MOV BL, 00H ; to count carry
- MOV SI, offset List
- Back: ADD AL, [SI]
- JC Label
- Back1: INC SI
- LOOP Back
- MOV Total, AX
- MOV Total+2, BL
- MOV AH, 4CH
- INT 21H
- Label: INC BL
- JMP Back1
- Main endp
- End Main
- 7. Write a program to find Largest No. in a block of data. Length of block is 0A. Store the
- maximum in location result. Title maximum in given series
- Dosseg
- .model small
- .stack 100h
- .data
- List db 80, 81, 78, 65, 23, 45, 89, 90, 10, 99
- Result db ?
- Written by CHANDRA THAPA (October 2012) 6
- .code
- Main proc
- MOV AX, @data
- MOV DS, AX
- MOV SI, offset List
- MOV AL, 00H
- MOV CX, 0AH
- Back: CMP AL, [SI]
- JNC Ahead
- MOV AL, [SI]
- Ahead: INC SI
- LOOP Back
- MOV Result, AL
- MOV AH, 4CH
- INT 21H
- Main endp
- End Main
- 8. Find number of times letter ëeí exist in the string ëexerciseí, Store the count at memory
- ans. Title string operation
- Dosseg
- .model small
- .stack 100h
- .data
- Written by CHANDRA THAPA (October 2012) 7
- String db ëexerciseí, $
- Ans db ?
- Length db $-String
- .code
- Main proc
- MOV AX, @data
- MOV DS, AX
- MOV AL,00H
- MOV SI, offset String
- MOV CX, Length
- Back: MOV BH, [SI]
- CMP BH, ëeí JNZ Label
- INC AL
- Label: INC SI
- LOOP Back
- MOV Ans, AL
- MOV AH, 4CH
- INT 21H
- Main endp
- End Main
- 9. Write an ALP to generate square wave with period of 200µs and address of output
- device is 55H for 8086 microprocessor. START: MOV AX, 01H
- OUT 30H, AX
- Written by CHANDRA THAPA (October 2012) 8
- ; to generate loop for 200 µs using system frequency 5MHz
- MOV BX, Count ;7T
- Label: DEC BX ;4T
- JNZ Label ;10T/7T
- MOV AX, 00H
- OUT 30H, AX
- MOV BX, Count
- Label1: DEC BX
- JNZ Label1
- JMP START
- Note: Find the value of Count using technique used in 8085 so that delay will be of 200 µs.
- 10. Write an assembly language program to count number of vowels in a given string. Title to count number of vowels in given line of a text
- Dosseg
- .model small
- .stack 100h
- .code
- Main proc
- MOV AX, @data
- MOV DS, AX
- MOV SI, offset String ;initialize p
- MOV CX, Len ;length in CX register
- MOV BL, 00 ;vowel count=0
- Written by CHANDRA THAPA (October 2012) 9
- Back: MOV AL, [SI]
- CMP AL, ëaí JB VOW
- CMP AL, ëzí ;Convert the character to upper case
- JA VOW
- SUB AL, 20H
- VOW: CMP AL, ëAí JNZ a3
- INC BL
- JMP a2
- a3: CMP AL, ëEí JNZ a4
- INC BL
- JMP a2
- a4: CMP AL, ëIí JNZ a5
- INC BL
- JMP a2
- a5: CMP AL, ëOí JNZ a6
- INC BL
- JMP a2
- a6: CMP AL, ëUí JNZ a2
- INC BL
- Written by CHANDRA THAPA (October 2012) 10
- a2: INC SI
- LOOP Back
- MOV Vowel, BL
- MOV AX, 4C00H
- INT 21H
- Main endp
- .data
- String db ëThe quick brown fox jumped over lazy sleeping dogí, $
- Len dw $-string
- Vowel db ?
- End Main
- 11. Write an 8086 ALP which will input the user name from the keyboard. If the user is
- ëPokharaí it will output ëThe username is validí else it will output ëInvalid user nameí. Note: This program is not verified in MASM so, please verify this program. This program can be
- done in the same approach as question 10, which is done above by comparing each character
- input.
- title input name and comparision
- dosseg
- .model small
- .stack 100h
- .data
- input db 7 dup(?)
- comparestring db 'Pokhara','$' outputstring1 db 'The username is valid','$' outputstring2 db 'The username is invalid','$'
- .code
- main proc
- mov ax, @data
- mov ds, ax
- ; read string
- mov dx, offset input
- Written by CHANDRA THAPA (October 2012) 11
- mov ah,0ah
- int 21h
- ;string comparision
- mov si, offset input
- mov di, offset comparestring
- mov cx,07h ;length of string in cx
- CLD ; DF-> direction flag clear i.e. autoincrement mode
- repe cmpsw ;compare words of two string if equal then ZF will be set
- JZ label1
- mov dx, offset outputstring2
- jmp label2
- label1: mov dx, offset outputstring1
- label2: mov ah, 0ah
- int 21h
- mov ah,4ch
- int 21h
- main endp
- end main
- Q: Convert binary to hexadecimal
- JMP HERE
- num db 1,0,0,1,0,0,1,1
- res db ?
- HERE:
- LEA SI, num
- MOV CL, 08H ; COUNT
- MOV AL, 00H ; RESULT
- AGAIN: MOV BL, [SI] ; FIRST ARRAY ITEM
- CMP BL, 01H
- JNE NEXT
- OR AL, 01H
- NEXT:
- cmp CL,01h
- JE end
- SHL AL, 01H
- INC SI
- LOOP AGAIN
- MOV res, AL
- end: HLT
- 1: To perform basic arithmetic operations using 8 bit and 16 bit number (Add, SUB, MUL, and DIV).
- Sol:
- Add:
- MOV AX,3000h
- MOV DS,AX
- MOV AX,[0200h]
- MOV BX,[0202h]
- ADD AX,BX
- HLT
- Sub:
- MOV AX,3000h
- MOV DS,AX
- MOV AX,[0200h]
- MOV BX,[0202h]
- SUB AX,BX
- HLT
- Multiply:
- MOV AX,3000h
- MOV DS,AX
- MOV AX,[0200h]
- MOV BX,[0202h]
- MUL BX
- HLT
- Division:
- MOV AX,3000h
- MOV DS,AX
- MOV AX,[0200h]
- MOV BX,[0202h]
- DIV BX
- HLT
- 2: Write an ALP to perform the sum and average of 5 numbers stored in the address location 2000h onwards and put the result in memory locations starting from 5000h onwards.
- Sol:
- mov bx,2000h
- mov al,[bx]
- incbx
- add al,[bx]
- incbx
- add al,[bx]
- incbx
- add al,[bx]
- incbx
- add al,[bx]
- mov bx,5000h
- mov [bx],al
- incbx
- mov cl,0005h
- div cl
- mov [bx],ax
- hlt
- 3: Write a program to count the number of 1’s in a given byte located in AL register..( Hint Use Rotate instruction : Eg : Input(AL) : 0A7 h Output : 5))
- Sol:
- Algorithm:
- 1. Move any number to al regiter.
- 2. Move 8 to dl register.
- 3. Rotate left al register 1 bit.
- 4. If carry bit =1 increment bl register.
- 5. Decrement dl register.
- 6. If dl register is not equal to zero goto Step No. 3,
- Else Stop.
- Code:
- mov al,0A7h
- mov dl,08h
- again: rol al,1
- jnc next
- incbl
- next:dec dl
- jnz again
- hlt
- Aim: To print the multiplication table for number 07.
- Algorithm:
- 1. Mov the number whose table is to be calculated to al – 07
- 2. Mov al to bl
- 3. Start counter cl = 01
- 4. Define the storing location in DI – 2000
- 5. Run a loop to print table.
- 6. Mul al by cl.
- 7. Store in DI
- 8. Inc cl and DI
- 9. Check if cl = 0A.
- 10. If yes hlt
- 11. Else loop to 6.
- Code:
- MOV AL,07H
- MOV BL, AL
- MOV CL, 01H
- MOV DI, 2000H
- BACK: MUL CL
- MOV [DI], AL
- INC DI
- MOV AL, BL
- INC CL
- CMP CL, 0AH
- JLE BACK
- HLT
- Aim: To Check whether the given number is prime or not
- Code:
- jmp here
- num db 11h
- here:mov al,num
- mov cl,al
- mov bl,02h
- again: div bl
- cmp ah,00h
- je notprime
- inc bl
- mov al,cl
- cmp al,bl
- jl again
- mov dl,'A'
- hlt
- notprime: mov dl,'B'
- hlt
- Aim: To generate the Fibonacci series for N terms.
- Code:
- mov al, 01h
- mov dl, 01h
- mov cl, 06h
- mov ch, al
- mov bx, 2000h
- mov [bx], al
- dec cl
- inc bx
- mov [bx], dl
- dec cl
- inc bx
- start: add al,dl
- mov [bx],al
- inc bx
- mov dl, ch
- mov ch, al
- dec cl
- cmp cl, 00h
- je finish
- jmp start
- finish: hlt
- Aim: To find the factorial of a number with and without using loop instruction
- Mov al,05h
- Mov bl,al
- Back: dec bl
- Mul bl
- Cmp bl,02h
- Jne back
- Hlt
- Aim: To perform the following string operations length, reverse and compare.
- Code:
- jmp Here
- msg db 'Try String_1$'
- msga db 'Try String_2$'
- msgrev db 20 dup(' ')
- Here:
- Mov SI,Offset msg
- Mov cx,00h
- Again:
- Mov al,[SI]
- cmp al,'$'
- je stop
- inc cx
- jmp last
- last:
- inc SI
- jmp Again
- stop:
- mov di,2000h
- mov [di],cx
- rev:
- mov bx,cx
- add cx, -1
- lea si, msg
- lea di, msgrev
- add si, bx
- add si, -1
- L1:
- mov al, [si]
- mov [di], al
- dec si
- inc di
- loop L1
- mov al, [si]
- mov [di], al
- inc di
- mov dl, '$'
- mov [di], dl
- Print:
- mov ah, 09h
- lea dx, msgrev
- int 21h
- comp:
- mov bx,00h
- mov bl,msg+1
- mov bh,msga+1
- mov SI,offset msg
- mov DI,offset msga
- L2:
- mov BL,[SI]
- cmp [DI],BL
- jne Lp1
- inc SI
- inc DI
- cmp [DI],"$"
- jne L2
- mov ax,00h
- mov 3000h,ax
- jmp end
- Lp1:
- mov ax,0Fh
- mov 3000h,ax
- end: hlt
- Aim: To Count the number of vowels in a given string
- Code:
- jmp Here
- MSG db 'ChAitanya$'
- Here: Mov SI,Offset MSG
- Mov ch,00h
- Again: Mov al,[SI]
- cmp al,'$'
- je stop
- Casea: cmp al,'a'
- jne casee
- inc ch
- jmp last
- Casee: cmp al,'e'
- jne casei
- inc ch
- jmp last
- Casei: cmp al,'i'
- jne caseo
- inc ch
- jmp last
- Caseo: cmp al,'o'
- jne caseu
- inc ch
- jmp last
- Caseu: cmp al,'u'
- jne Case1
- inc ch
- jmp last
- Case1: cmp al,'A'
- jne case2
- inc ch
- jmp last
- Case2: cmp al,'E'
- jne case3
- inc ch
- jmp last
- Case3: cmp al,'I'
- jne case4
- inc ch
- jmp last
- Case4: cmp al,'O'
- jne case5
- inc ch
- jmp last
- Case5: cmp al,'U'
- jne last
- inc ch
- jmp last
- last: inc SI
- jmp Again
- stop: mov di,2000h
- mov [di],ch
- hlt
- Aim: Analyse the string Instruction MOVSB, CMPS, SCAS etc
- Code:
- jmp here
- msg db 'Hello$'
- msg1 db 'Bello$'
- here:
- mov cx,0006h
- lea si,msg
- mov di,0300h
- rep movsb
- cld
- mov cx,0006h
- lea di,msg
- mov al,'e'
- repnz scasb
- mov cx,0006h
- lea si,msg
- lea di,msg1
- repe cmpsb
- hlt
- Q2. Smallest element in an array
- .model small
- .data
- arr db 0Bh, 02h, 04h, 07h, 06h
- .code
- start:
- mov ax, @data
- mov ds, ax
- mov si, offset arr
- mov bl, [si]
- mov cl, 04h
- inc si
- loop1:
- cmp cl, 00h
- je ecmp
- cmp bl, [si]
- jg change_small
- inc [si]
- dec cl
- jmp loop1
- change_small:
- mov bl, [si]
- jmp loop1
- ecmp:
- mov ah, 4ch
- int 21h
- end start
- end
- Q1. Factorial
- .MODEL SMALL
- .DATA
- .CODE
- START:
- MOV AX, @DATA
- MOV DS, AX
- MOV AL, 05H
- MOV BL, AL
- MOV CL, 02H
- FACT:
- CMP CL, BL
- JE EF
- MUL CL
- INC CL
- JMP FACT
- EF:
- MOV AH, 4CH
- INT 21H
- END START
- END
- Q3. Fibonacci upto n terms
- .model small
- .data
- .code
- start:
- mov ax, @data
- mov ds, ax
- mov al, 00h
- mov bl, 01h
- mov cl, 05h
- mov si, 2000h
- mov [si], al
- inc si
- mov [si], bl
- inc si
- loop1:
- add al, bl
- mov ah, al
- mov [si], ah
- inc si
- mov al, bl
- mov bl, ah
- loop loop1
- mov ah, 4ch
- int 21h
- end start
- end
- Code:
- .MODEL SMALL
- .DATA
- ; No data defined
- .CODE
- start:
- MOV AX,@DATA MOV DS, AX MOV AL, 09h MOV BL, 04H ADD AL,BL
- MOV AH, 4Ch
- INT 21h
- END start
- End
- Procedure:
- 1. Open DOSBOX and execute the following commands -
- Z:\>mount c ~ /desktop
- Z:\>c:
- C:\>cd desktop
- C:\>cd MASM
- MASM:\>edit one.asm
- 2. Type the code and save.
- 3. Now execute the following commands -
- MASM:\>Masm one.asm
- Press ‘enter’ three times
- MASM:\>Link one.obj
- Press ‘enter’ three times
- Debug one.exe
- 4. Use the following commands as required -
- -t for line by line execution
- -q for quit
- -d ds:2000 to display memory content
- -e ds:2000 to enter the data in memory
- AIM: SQUARE ROOT OF A NUMBER
- CODE:
- mov [1000],09h
- mov ax,[1000]
- mov bx, 0ffffh
- mov cx,00
- l1:
- inc cx
- add bx,02
- sub ax,bx
- jnz l1
- mov [2000],cx
- hlt
- Q.2) Write an ALP to convert a hexadecimal number to binary pattern and store at 2000:3000h locations.
- Code:
- DATA SEGMENT
- STR1 DB "BINARY NUMBER IS : $"
- STR2 DB "DECIMAL NUMBER IS : $"
- BSTR DB 20 DUP("$")
- RSTR DB 20 DUP("$")
- NEWLINE DB 13,10,"$"
- CNT DB 0
- N DB 2
- H DB 16
- D DB 10H
- NUM DB ?
- SNUM DB ?
- HNUM DB 19H
- DATA ENDS
- CODE SEGMENT
- ASSUME CS:CODE,DS:DATA
- START:
- MOV AX,DATA
- MOV DS,AX
- ;CONVERT HEXA TO DECIMAL
- MOV CX,00
- MOV DX,00
- L6:MOV AX,00
- MOV AL,HNUM
- DIV D
- MOV HNUM,AL
- MOV BX,AX
- MOV CL,CNT
- MOV AX,1
- L5: CMP CL,00
- JE L7
- MUL H
- SUB CL,1
- JMP L5
- L7: MUL BH
- ADD DX,AX
- ADD CNT,1
- CMP HNUM,0
- JG L6
- MOV NUM,DL
- ;CONVERT DECIMAL TO BINARY
- LEA SI,BSTR
- LEA DI,RSTR
- L1: MOV AX,00
- MOV AL,NUM
- DIV N
- ADD AH,30H
- MOV BYTE PTR[SI],AH
- INC SI
- MOV NUM,AL
- CMP AL,0
- JG L1
- DEC SI
- L2:MOV BL,BYTE PTR[SI]
- MOV BYTE PTR[DI],BL
- DEC SI
- INC DI
- CMP SI,0
- JNE L2
- MOV AH,09H
- LEA DX,STR1
- INT 21H
- MOV AH,09H
- LEA DX,RSTR
- INT 21H
- MOV AH,4CH
- INT 21H
- CODE ENDS
- END START
- Question: Change the sign of element
- MOV DL, -01H; VARIABLE WHOSE SIGN IS TO BE CHANGED
- MOV BL, DL ; STORING THE NUMBER
- MOV AL, DL
- ADD AL, DL
- SUB DL, AL ; THE RESULT, THAT IS THE NUMBER WITH THE CHANGED SIGN IS STORED IN DL
- HLT
- Question: even odd
- MOV AX, 05H
- MOV BL, 02H
- DIV BL
- MOV DL, AH ; IF DL IS 0, THE NUMBER IS EVEN ELSE IT IS ODD
- Question:
- MOV DL, 15H; THE NUMBER WHOSE DIVISORS ARE TO BE FOUND
- MOV SI, 500H; SETTING THE ADDRESS
- MOV BL, 01H
- NEXT:
- MOV AH, 000H
- MOV AL,DL
- DIV BL
- CMP AH, 0H
- JE TRUE
- JMP PART2
- PART2:
- INC BL
- CMP DL, BL
- JE STOP
- LOOP NEXT
- TRUE:
- MOV [SI], BL
- INC SI
- JMP PART2
- STOP:
- MOV [SI], BL
- HLT
- Question: Reverse a number
- MOV DL, 32H
- MOV SI, 500H
- MOV [SI], DL
- MOV AL, DL
- MOV BL, 10H
- MOV BH, 10H
- MOV CL, 0H;CL IS DIGIT
- MOV CH, 0H;CH IS REVERSE
- WLOOP:
- CMP DL, 0
- JLE STOP
- DIV BL
- MOV CL, AH
- ; DIGIT=NUM%10
- MOV DL, AL; NUM=NUM/10
- ;REV=REV*10 + DIGIT
- MOV AH, 000H
- MOV DH, AL
- MOV AL, CH
- MUL BH
- MOV CH, AL
- ADD CH, CL
- MOV AL, DH
- JMP WLOOP; CONTINUE LOOP
- STOP:
- MOV AH, [SI]
- MOV AL, CH
- HLT
- Question 1:
- Find the smallest number among three numbers in registers.
- Code for the execution of the program
- MOV AL, 16H
- MOV BL, 25H
- MOV CL, 47H
- MOV DL, AL
- CMP DL, BL
- JNLE NEXT1
- JMP NEXT2
- NEXT1:
- MOV DL, BL
- JMP NEXT2
- NEXT2:
- CMP DL, CL
- JNLE NEXT3
- HLT
- NEXT3:
- MOV DL, CL
- HLT
- Question 4
- Identify all divisible numbers for a given number
- Code for the execution of the program
- MOV DL, 08H; THE NUMBER WHOSE DIVISORS ARE TO BE FOUND
- MOV SI, 500H; SETTING THE ADDRESS
- MOV BL, 01H
- NEXT:
- MOV AH, 000H
- MOV AL,DL
- DIV BL
- CMP AH, 0H
- JE TRUE
- JMP PART2
- PART2:
- INC BL
- CMP DL, BL
- JE STOP
- LOOP NEXT
- TRUE:
- MOV [SI], BL
- INC SI
- JMP PART2
- STOP:
- MOV [SI], BL
- HLT
- Question 5
- Print the given number in reverse
- Code for the execution of the program
- MOV DL, 15H ; THE NUMBER TO BE REVERSED
- MOV SI, 500H
- MOV [SI], DL
- MOV AL, DL
- MOV BL, 10H
- MOV BH, 10H
- MOV CL, 0H;CL IS DIGIT
- MOV CH, 0H;CH IS REVERSE
- WLOOP:
- CMP DL, 0
- JLE STOP
- DIV BL
- MOV CL, AH
- ; DIGIT=NUM%10
- MOV DL, AL; NUM=NUM/10
- ;REV=REV*10 + DIGIT
- MOV AH, 000H
- MOV DH, AL
- MOV AL, CH
- MUL BH
- MOV CH, AL
- ADD CH, CL
- MOV AL, DH
- JMP WLOOP; CONTINUE LOOP
- STOP:
- MOV AH, [SI]
- MOV AL, CH
- HLT
- ;String, Program to input a string and print it
- .model small
- .stack 100h
- .data
- var1 db 100 dup('$')
- msg1 db 'Enter the password: $'
- msg2 db 'Yes$'
- msg3 db 'No$'
- .code
- main proc
- mov ax, @data
- mov ds, ax
- mov si, offset var1
- mov dx, offset msg1
- mov ah, 9
- int 21h
- mov cl, 0h
- input:
- mov ah,1
- int 21h
- cmp al, 13 ; 13 is ascii for return character
- je check
- mov [si], al
- inc si
- inc cl
- jmp input
- check:
- cmp cl, 6h
- je check2
- jmp false
- check2:
- mov si, offset var1
- mov ah, [si]
- cmp ah,30h ;hex for 0 is 30 and goes on to 39
- jge true0
- jmp false
- true0:
- cmp ah, 39h; hex for 9 is 39
- jle check30 ; checked for first number
- jmp false
- check 30:
- mov ch, 0h; for numbers
- mov cl, 0h; for alphabets
- mov si, offset var1
- check3: ;checking for 4 alphabets and two numbers
- mov ah, [si]
- cmp ah, 30h
- jge number00
- jmp alphabet
- number00:
- cmp ah, 39h
- jle alphabet
- jmp number
- alphabet:
- inc si
- inc cl
- mov ah, [si]
- cmp ah, '$'
- jmp pass0
- jmp check3
- number:
- inc si
- inc ch
- mov ah, [si]
- cmp ah, '$'
- jmp pass0
- jmp check3
- ;Checking count of alphabets and numbers
- pass0:
- cmp cl, 04h
- je pass1
- jmp false
- pass1:
- cmp ch, 02h
- je true
- jmp false
- ;Now printing moment of truth
- true:
- ; new line feed
- mov dx, 10
- mov ah, 2
- int 21h
- ;carriage return
- mov dx, 13
- mov ah, 2
- int 21h
- mov dx, offset msg2
- mov ah, 9
- int 21h
- jmp programend
- false:
- mov dx, 10
- mov ah, 2
- int 21h
- ;carriage return
- mov dx, 13
- mov ah, 2
- int 21h
- mov dx, offset msg3
- mov ah, 9
- int 21h
- jmp programend
- programend:
- mov ah, 4ch
- int 21h
- main endp
- end main
- Pallindrome
- .MODEL SMALL ;Palindrama
- .STACK 100
- .DATA
- STR1 DB 'hannah$'
- .CODE
- MOV AX, @DATA
- MOV DS, AX
- MOV SI, OFFSET STR1
- MOV DI, OFFSET STR1
- MOV BL, '$'
- PHASE1:; THIS PHASE WILL INCREMENT DI TO THE LAST POSITION OF THE STRING
- MOV AL, [DI]
- CMP AL, BL
- JE FLAG1
- INC DI
- JMP PHASE1
- FLAG1:
- DEC DI
- PHASE2:; THIS PHASE WILL COMPARE THE VALUES OF ADDRESSES OF DI WITH SI
- CMP SI, DI
- JE PASS_CASE
- CMP SI, DI
- JGE PASS_CASE
- MOV AL, [SI]
- MOV BL, [DI]
- CMP AL, BL
- JNE FAIL_CASE
- INC SI
- DEC DI
- JMP PHASE2
- FAIL_CASE:; THE STRING IS NOT PALINDROME
- MOV DH, 5
- JMP STOP
- PASS_CASE:
- MOV DH, 10
- JMP STOP
- STOP:
- MOV AH, 4CH
- INT 21H
- END
- 16 bit :
- ADDITION
- DATA SEGMENT
- DATA ENDS
- CODE SEGMENT
- ASSUME CS : CODE, DS : DATA
- MOV AX, DATA
- MOV DS, AX
- MOV AX, 4261H
- ADD AX, 1234H
- HLT
- CODE ENDS
- END
- SUBSTRACTION
- DATA SEGMENT
- DATA ENDS
- CODE SEGMENT
- ASSUME CS : CODE, DS : DATA
- MOV AX, DATA
- MOV DS, AX
- MOV AX, 4261H
- SUB AX, 1234H
- HLT
- CODE ENDS
- END
- MULTIPLICATION
- DATA SEGMENT
- A DW 0105H
- B DW 0210H
- C DW ?
- DATA ENDS
- CODE SEGMENT
- ASSUME CS:CODE, DS:DATA
- START:
- MOV AX,DATA
- MOV DS,AX
- MOV AX,0000H
- MOV BX,0000H
- MOV AX,A
- MOV BX,B
- IMUL B
- MOV C,AX
- INT 3
- CODE ENDS
- END START
- DIVISION
- DATA SEGMENT
- A DW 8844H
- B DW 0004H
- C DW ?
- DATA ENDS
- CODE SEGMENT
- ASSUME DS:DATA, CS:CODE
- START:
- MOV AX,DATA
- MOV DS,AX
- MOV AX,A
- MOV BX,B
- DIV BX
- MOV C,BX
- INT 3
- CODE ENDS
- END START
- Largest:
- data segment
- STRING1 DB 08h,13h,18h,0Fh,09h
- res db ?
- data ends
- code segment
- assume cs:code, ds:data
- start: mov ax, data
- mov ds, ax
- mov cx, 04h
- mov bl, 00h
- LEA SI, STRING1
- up:
- mov al, [SI]
- cmp al, bl
- jl nxt
- mov bl, al
- nxt:
- inc si
- dec cx
- jnz up
- mov res,bl
- code ends
- end start
- Ascending order:
- CODE SEGMENT
- ASSUME CS:CODE
- ORG 1000H
- START:MOV SI,1100H
- MOV CL,[SI]
- DEC CL
- REPEAT: MOV SI,1100H
- MOV CH,[SI]
- DEC DL
- REPCOM: MOV AL,[SI]
- INC SI
- CMP AL,[SI]
- JC AHEAD
- XCHG AL,[SI]
- XCHG AL,[SI-1]
- AHEAD: DEC CH
- JNZ REPCOM
- DEC CL
- JNZ REPEAT
- HLT
- Search element in an array:
- jmp here
- arr db 02h,04h,07h,09h,01h
- here:mov cx,05h
- mov dl,00h
- mov si, offset arr
- again:mov al,[si]
- cmp al,04h
- jne next
- inc dl
- next:inc si
- loop again
- hlt
- Factorial of Hexa Decimal Number
- MOV CX,06h
- MOV AX,01h
- abc: mul CX
- dec CX
- jnz abc
- hlt
- QUESTION: Write an ALP to count no.of positive and negative numbers.
- SOLUTION:
- Code:
- data segment
- num db 9,8,7,6,-3,-5,-6,-7
- len dw $-num
- p_cnt db 0h
- n_cnt db 0h
- data ends
- code segment
- assume cs:code ds:data
- start:
- mov ax,data
- mov ds,ax
- mov cx,len
- lea si,num
- looper:
- mov al,[si]
- cmp al,0
- jg pos
- jl nega
- pos:
- inc bh
- jmp rest
- nega:
- inc dh
- jmp rest
- rest:
- inc si
- dec cx
- cmp cx,0
- jg looper
- mov p_cnt,bh
- mov n_cnt,dh
- mov ah,4ch
- int 21h
- code ends
- end start
- UESTION: Write an ALP for traffic light system and stepper motor.
- SOLUTION:
- TRAFFIC LIGHT:
- CODE:
- #start=Traffic_lights.exe#
- name "traffic"
- mov ax,all_red
- out 4, ax
- mov si,offset situation
- next:
- mov ax,[si]
- out 4 ,ax
- mov cx,4Ch
- mov dx, 4840h
- mov ah, 86h
- int 15h
- add si,2
- cmp si, sit_end
- jb next
- mov si, offset situation
- jmp next
- situation dw 0000-0011_0000_1100b
- s1 dw 0000_0110_1001_1010b
- s2 dw 0000_1000_0110_0001b
- s3 dw 0000_1000_0110_0001b
- s4 dw 0000_0100_1101_0011b
- sit_end=$
- all_red equ 0000_0010_0100_1001b
- STEPPER MOTOR:
- CODE:
- #start=stepper_motor.exe#
- name "stepper"
- #make_bin#
- steps_before_direction_change=20h
- jmp start
- datcw db 0000_0110b
- db 0000_0100b
- db 0000_0011b
- db 0000_0010b
- datccw db 0000_0011b
- db 0000_0001b
- db 0000_0110b
- db 0000_0010b
- datcw_fs db 0000_0001b
- db 0000_0011b
- db 0000_0110b
- db 0000_0000b
- datccw_fs db 0000_0100b
- db 0000_0110b
- db 0000_0011b
- db 0000_0000b
- start:
- mov bx, offset datcw
- mov si,0
- mov cx,0
- next_step:
- wait:in al,7
- test al, 10000000b
- jz wait
- mov al, [bx][si]
- out 7,al
- inc si
- cmp si,4
- jb next_step
- mov si,0
- inc cx
- cmp cx, steps_before_direction_change
- jb next_step
- mov cx,0
- add bx, 4
- cmp bx, offset datccw_fs
- jbe next_step
- mov bx, offset datcw
- jmp next_step
- Smallest:
- data segment
- STRING1 DB 08h,14h,02h,0Fh,04h
- res db ?
- data ends
- code segment
- assume cs:code, ds:data
- start: mov ax, data
- mov ds, ax
- mov cx, 04h
- mov bl, 79h
- LEA SI, STRING1
- up:
- mov al, [SI]
- cmp al, bl
- jge nxt
- mov bl, al
- nxt:
- inc si
- dec cx
- jnz up
- mov res,bl
- int 3
- code ends
- end start
- File handling:
- .stack 100h
- .data
- text db "Hello World$"
- filename db "file.txt",0
- handler dw ?
- .code
- mov ax,@data
- mov ds,ax
- mov ah,3ch
- mov cx,0
- mov dx,offset filename
- int 21h
- mov handler,ax
- mov ah,40h
- mov bx,handler
- mov cx,15
- mov dx, offset text
- int 21h
- mov ah,3eh
- mov bx,handler
- int 21h
- mov ax,4c00h
- int 21h
- delete file:
- .MODEL SMALL
- .DATA
- FILE DB 'C:\emu8086\MyBuild\file.txt',0
- MSG DB 'File Deleted','$'
- .CODE
- START: MOV AX,@DATA
- MOV DS,AX
- LEA DX,FILE
- MOV AH,41H
- INT 21H
- JC EXIT
- LEA DX,MSG
- MOV AH,09H
- INT 21H
- EXIT:MOV AH,4CH
- INT 21H
- END START
- LAB ASSIGNMENT – 6
- Name- Akash Goyal
- Reg. no- 16BCE0592
- Course Code – CSE2006
- Course Title – Microprocessor and Interfacing
- Slot- L21-22
- Q.1 Write the ALP codes for String Manipulation?
- (A) Reading a string from the user:-
- Code:-
- .model small
- .stack 64
- .data
- a db ?
- a1 db ?
- .code
- start:mov ax,@data
- mov ds,ax
- mov al,offset a1
- mov ah,01h
- int 21h
- mov cl,al
- again:mov si,offset a
- mov ah,01h
- int 21h
- dec cl
- jnz again
- Screen Shot of the code:-
- Screen Shot of the output
- (b) Palindrome for numeric string:-
- Code:-
- .model small
- .stack 64
- .data
- m1 db ?
- m2 db 'Pallindrome$'
- m3 db 'Not pallindrome$'
- .code
- .start:mov ax,@data
- mov ds,ax
- mov cl,04h
- mov di,4000h
- again: mov si,offset m1
- mov ah,01h
- int 21h
- inc si
- dec cl
- jnz again
- mov ax,[si]
- mov bl,10
- mov cl,04h
- again1:div bl
- mov di,dx
- mov bl,al
- inc di
- dec cl
- jnz again1
- mov al,[si]
- mov bl,[di]
- cmp bl,al
- je one
- mov dx,offset m3
- mov ah,09h
- int 21h
- one:mov dx,offset m2
- mov ah,09h
- int 21h
- stop:nop
- Screen Shot of the Output:-
- (C) Palindrome for Word string:-
- Code:-
- data segment
- str1 db 'MADAM','$'
- strlen1 dw $-str1
- strrev db 20 dup(' ')
- str_pallin db 'String is pallindrome','$'
- str_not_pallin db 'String not pallindrome','$'
- data ends
- Code segment
- Assume cs:code,ds:data
- Begin:
- mov ax,data
- mov cl,05h
- mov ds,ax
- mov es,ax
- mov cx,strlen1
- mov cx,-2
- lea si,str1
- lea di,strrev
- add si,strlen1
- add si,-2
- L1:mov al,[si]
- mov [di],al
- dec si
- inc di
- dec cl
- mov al,[si]
- mov [di],al
- inc di
- mov dl,'$'
- mov [di],dl
- mov cx,strlen1
- Pallin_check:
- lea si,str1
- lea di,strrev
- repe cmpsb
- jne Not_pallin
- Pallin:
- mov ah,09h
- lea dx,str_not_pallin
- int 21h
- jmp Exit
- Not_pallin:
- mov ah,09h
- lea dx,str_pallin
- int 21h
- Exit:
- mov ax,4c00h
- int 21h
- Code Ends
- End Begin
- Screen Shot of the output:-
- (D) To find the number of vowels present in the string:-
- Code:-
- var db 'abacus$'
- mov bx, 00h
- casea:
- cmp var[bx],'a'
- jne casee
- mov al,[0200h]
- inc al
- mov [0200h],al
- casee:
- cmp var[bx],'e'
- jne casei
- mov al,[0201h]
- inc al
- mov [0201h],al
- casei:
- cmp var[bx],'i'
- jne caseo
- mov al,[0202h]
- inc al
- mov [0202h],al
- caseo:
- cmp var[bx],'o'
- jne caseu
- mov al,[0203h]
- inc al
- mov [0203h],al
- caseu:
- cmp var[bx],'u'
- jne check
- mov al,[0204h]
- inc al
- mov [0204h],al
- check:
- inc bx
- cmp var[bx],'$'
- jne casea
- hlt
- Screen Shot of the output:-
- Q.2 Write the ALP code for LED 7 segment register ?
- (A) Without delay:-
- Code :-
- #start=led_display.exe#
- mov ax,01h
- again:out 199,ax
- inc ax
- jmp again
- mov ah,4ch
- Screen Shot of the code:-
- Screen Shot of the output:-
- (B). With delay:-
- Code:-
- #start=led_display.exe#
- mov ax,01h
- again: out 199,ax
- inc ax
- mov cl,05h
- delay:dec cl
- jnz delay
- jmp again
- mov ah,4ch
- int 21h
- Screen Shot of the code:-
- Screen Shot of the output:-
- (b) ALP for Block transfer of data :-
- Code:-
- .model small
- .stack 64
- .data
- .code
- start:mov ax,@data
- mov si,2000h
- mov [si],12h
- inc si
- mov [si],34h
- inc si
- mov [si],56h
- inc si
- mov [si],74h
- inc si
- mov [si],94h
- mov di,3000h
- mov si,2000h
- mov cl,05h
- again:
- mov bl,[si]
- mov [di],bl
- inc si
- inc di
- dec cl
- jnz again
- int 21h
- end start
- end
- Fibonacci code:
- Code:¬
- jmp here
- x db 00H
- Y db 01H
- n db 05H
- here: mov al,x
- mov cl,n
- mov bl,y
- mov si,2000h
- again: inc si
- add al,bl
- xchg al,bl
- loop again
- mov [si],bl
- hlt
- 2. ALP for NCR and NPR (Note: nCr = n! /r! (n-r)! and
- NPR =
- n!/(n-r)!
- Code:-
- a) NCR
- .model small
- .stack 64
- .data
- .code
- mov al,05h
- mov dl,03h
- mov cl,al
- sub cl,dl
- mov bl,al
- sub bl,01h
- again: mul bl
- dec bl
- Jnz again
- mov bl,dl
- mov dl,al
- mov al,bl
- sub bl,01h
- fac: mul bl
- dec bl
- Jnz fac
- mov bl,cl
- mov cl,al
- mov al,bl
- sub bl,01h
- fact: mul bl
- dec bl
- Jnz fact
- mov bl,cl
- mul bl
- mov bl,al
- mov al,dl
- div bl
- b) NPR
- CODE:
- .model small
- .stack 64
- .data
- .code
- mov al,05h
- mov bl,al
- sub bl,01h
- mov dl,03h
- mov cl,dl
- mov dl,al
- sub dl,cl
- again: mul bl
- dec bl
- Jnz again
- mov bl,dl
- mov dl,al
- mov al,bl
- sub bl,01h
- fac:mul bl
- dec bl
- Jnz
- fac mov bl,al
- mov al,dl
- div bl
- CSE2006 - LAB EXPERIMENT-1
- Simardeep Singh
- 16BCE0198
- Q) Write an ALP using 8086 instructions to generate and add the first 10 even numbers and
- save the numbers and result in memory location Num and Sum.
- CODE:
- MOV CL,10
- MOV AX,0
- MOV BX,0
- BACK:
- ADD BX,2
- ADD AX, BX
- DEC CL
- JNZ BACK
- HLT
- CSE-2006: EXPERIMENT – 2
- Name: Simardeep Singh
- Registration Number: 16BCE0198
- Q). Write an 8086 alp to search for a given 16-bit value using binary search in an array of 16 bit
- numbers, which are in sorted. Display the status in any one of the registers (found or not) .If the
- element is found the position of the element in the array is to be displayed.
- Answer:
- Source code:
- DATA SEGMENT
- ARR DW 0000H,1111H,2222H,3333H,4444H,5555H,6666H,7777H,8888H,9999H
- LEN DW ($-ARR)/2
- KEY EQU 7777H
- MSG1 DB "KEY IS FOUND AT "
- RES DB " POSITION",13,10,"$"
- MSG2 DB "KEY NOT FOUND !!! .$"
- DATA ENDS
- CODE SEGMENT
- ASSUME DS:DATA CS:CODE
- START:
- MOV AX,DATA
- MOV DS,AX
- MOV BX,00
- MOV DX,LEN
- MOV CX,KEY
- AGAIN:CMP BX,DX
- JA FAIL
- MOV AX,BX
- ADD AX,DX
- SHR AX,1
- MOV SI,AX
- ADD SI,SI
- CMP CX,ARR[SI]
- JAE BIG
- DEC AX
- MOV DX,AX
- JMP AGAIN
- BIG: JE SUCCESS
- INC AX
- MOV BX,AX
- JMP AGAIN
- SUCCESS:ADD AL,01
- ADD AL,'0'
- MOV RES,AL
- LEA DX,MSG1
- JMP DISP
- FAIL: LEA DX,MSG2
- DISP: MOV AH,09H
- INT 21H
- MOV AH,4CH
- INT 21H
- CODE ENDS
- END START
- Output:
- CSE -2006 LAB ASSESMENT-3
- Simardeep Singh
- 16BCE0198
- Q) Write an ALP to sort in ascending order using bubble sort algorithm that lets the user type
- a given set of byte sized unsigned numbers in memory. The sorted elements should replace
- the original unsorted elements in memory
- ALP CODE:
- org 100h
- .data
- str db 10,13,"Enter Values: $"
- str1 db 0dh,0ah,"Bubble Sorted: $"
- array db 10dup(0)
- .code
- mov ah,9
- lea dx,str
- int 21h
- mov cx,10
- mov bx,offset array
- mov ah,1
- inputs:
- int 21h
- mov [bx],al
- inc bx
- Loop inputs
- mov cx,10
- dec cx
- nextscan:
- mov bx,cx
- mov si,0
- nextcomp:
- mov al,array[si]
- mov dl,array[si+1]
- cmp al,dl
- jc noswap
- mov array[si],dl
- mov array[si+1],al
- noswap:
- inc si
- dec bx
- jnz nextcomp
- loop nextscan
- mov ah,9
- lea dx,str1
- int 21h
- mov cx,10
- mov bx,offset array
- print:
- mov ah,2
- mov dl,[bx]
- int 21h
- inc bx
- loop print
- ret
- SCREENSHOT:
- OUTPUT:
- LAB ASSESSMENT-04
- NAME: Simardeep Singh
- REG NO: 16BCE0198
- Q-1) Highlights the services provided by various BIOS and DOS Interrupts.
- DOS and BIOS interrupts are used to perform some very useful functions, such as displaying
- data to the monitor, reading data from keyboard, etc. „ They are used by identifying the
- interrupt option type, which is the value stored in register AH and providing, whatever extra
- information that the specific option requires.
- BIOS Interrupt 10H
- Option 0H – Sets video mode.
- Registers used: AH = 0H, AL = Video Mode.
- 3H - CGA Color text of 80X25
- 7H - Monochrome text of 80X25
- Ex: MOV AH,0 MOV AL,7 INT 10H
- Option 2H – Sets the cursor to a specific location.
- Registers used: AH = 2H, BH = 0H selects Page 0.
- DH = Row position. DL = Column position.
- Ex: MOV AH,2
- MOV BH,0
- MOV DH,12
- MOV DL,39
- INT 10H
- Option 6H – Scroll window up. This interrupt is also used to clear the screen when you set AL = 0.
- Registers used:
- AH = 6H
- AL = number of lines to scroll.
- BH = display attribute.
- CH = y coordinate of top left.
- CL = x coordinate of top left.
- DH = y coordinate of lower right.
- DL = x coordinate of lower right
- CLEAR SCREEN EXAMPLES
- MOV AH,6
- MOV AL,0
- MOV BH,7
- MOV CH,0
- MOV CL,0
- MOV DH,24
- MOV DL,79
- INT 10H
- The code above may be shortened by using AX, BX and DX registers to move word size data
- instead of byte size data.
- Option 7H – Scroll window down. This interrupt is also used to clear the screen when you
- set AL = 0. Registers used:
- AH = 7H
- AL = number of lines to scroll.
- BH = display attribute.
- CH = y coordinate of top left.
- CL = x coordinate of top left.
- DH = y coordinate of lower right.
- DL = x coordinate of lower right.
- Option 8H – Read a character and its attribute at the cursor position.
- Registers used:
- AH = 8H and returned attribute value.
- AL = Returned ASCII value.
- BH = display page.
- Option 9H – Write a character and its attribute at the cursor position. „
- Registers used:
- AH = 9H.
- AL = ASCII value.
- BH = display page.
- BL = attribute.
- CX = number of characters to write.
- Attribute Definition
- Monochrome display attributes
- Blinking „ D7 = 0 - Non-blinking
- D7 = 1 - Blinking Intensity
- D3=0 - Normal intensity
- D3=1 - Highlighted intensity
- Background and foreground
- D6 D5 D4 and D2 D1 D0
- White = 0 0 0
- Black = 1 1 1
- DOS Interrupt 21H
- Option 1 – Inputs a single character from keyboard and echoes it to the monitor.
- Registers used:
- AH = 1
- AL = the character inputted from keyboard.
- Ex: MOV AH,1
- INT 21H
- Option 2 – Outputs a single character to the monitor.
- Registers used:
- AH = 2
- DL = the character to be displayed.
- Ex:
- MOV AH,2
- MOV DL,’A’
- INT 21H
- Option 9 – Outputs a string of data, terminated by a $ to the monitor.
- Registers used:
- AH = 9
- DX = the offset address of the data to be displayed.
- Ex:
- MOV AH, 09
- MOV DX, OFFSET MESS1
- INT 21H
- Option 0AH – Inputs a string of data from the keyboard.
- Registers used:
- AH = 9
- DX = the offset address of the location where string will be stored.
- DOS requires that a buffer be defined in the data segment. It should be defined as follows:
- 1st byte contains the size of the buffer.
- 2nd byte is used by DOS to store the number of bytes stored.
- Ex: DATA
- BUFFER1 DB 15,
- 15 DUP (FF)
- MOV AH,0AH
- MOV DX, OFFSET BUFFER1
- INT 21H
- Assume “Go Tigers!” was entered on the keyboard.
- BUFFER1 = 10,10,’Go
- Option 4CH – Terminates a process, by returning control to a parent process or to DOS. „
- Registers used:
- AH = 4CH
- AL = binary return code.
- Ex:
- MOV AH, 4CH
- INT 21H
- Option 4CH – Terminates a process, by returning control to a parent process or to DOS.
- Registers used:
- AH = 4CH
- AL = binary return code.
- Ex:
- MOV AH,4CH
- INT 21H
- Q-2) Convert the following decimal number 178.625 into short real format.
- (178.625)10
- (10110010.101)2
- 1.0110010101 * 107 normalisation
- 111+01111111= 10000110
- Result
- Sign= 0
- Exponent= 10000110
- Significand= 01100101010000000000000
- Short real format=01000011001100101010000000000000 = 4332A000h
- CSE2006: Microprocessors and Interfacing
- Assignment: 6
- Name: Resham
- Reg Number: 16BCE0971
- 1. Write an 8086 ALP which will input the organisation name from the keyboard. If the name is
- 'VIT' it will output “Permission granted” else it will display the message “Wrong details” using
- DOS interrupt.
- Code:
- DATA SEGMENT
- MSG1 DB 10,13,'ENTER ORGANIZATION NAME : $'
- MSG2 DB 10,13,'WRONG DETAILS $'
- MSG3 DB 10,13,'PERMISSION GRANTED $'
- MSG4 DB 10,13,'LENGTH NOT EQUAL $'
- STR1 DB "VIT"
- P1 LABEL BYTE
- M1 DB 0FFH
- L1 DB ?
- P11 DB 0FFH DUP ('$')
- DATA ENDS
- DISPLAY MACRO MSG
- MOV AH,9
- LEA DX,MSG
- INT 21H
- ENDM
- CODE SEGMENT
- ASSUME CS:CODE,DS:DATA
- START:
- MOV AX,DATA
- MOV DS,AX
- DISPLAY MSG1
- LEA DX,P1
- MOV AH,0AH
- INT 21H
- CMP L1,3
- JNE NOTEQUAL
- LEA SI,STR1
- LEA DI,P11
- MOV CX,3
- CHECK:
- MOV AL,[SI]
- CMP [DI],AL
- JNE NOPASWD
- INC SI
- INC DI
- LOOP CHECK
- DISPLAY MSG3
- JMP EXIT
- NOTEQUAL:
- DISPLAY MSG4
- NOPASWD:
- DISPLAY MSG2
- JMP EXIT
- EXIT: MOV AH,4CH
- INT 21H
- CODE ENDS
- END START
- Output:
- 2. Write an ALP to convert the given hexadecimal number to binary and perform the 2's
- complement of the resultant.
- a) 8BE2H
- Code:
- .model small
- .data
- a dw 8BE2H
- .code
- mov ax, @data ; Initialize data section
- mov ds, ax
- mov ax, a ; Load number1 in ax
- Flowchart 2
- neg ax ; find 2's compement. Result
- in ax
- mov ch, 04h ; Count of digits to be displayed
- mov cl, 04h ; Count to roll by 4 bits
- mov bx, ax ; Result in reg bx
- l2: rol bx, cl ; roll bl so that msb comes
- to lsb
- mov dl, bl ; load dl with data to be
- displayed
- and dl, 0fH ; get only lsb
- cmp dl, 09 ; check if digit is 0-9 or
- letter A-F
- jbe l4
- add dl, 07 ; if letter add 37H else only
- add 30H
- l4: add dl, 30H
- mov ah, 02 ; Function 2 under INT 21H
- (Display character)
- int 21H
- dec ch ; Decrement Count
- jnz l2
- mov ah, 4cH ; Terminate Program
- int 21H
- end
- Output:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement