Microprocessor Lab
Download TASM (Turbo Assembler)
Paste debug.exe at TASM folder in C drive.
Installing Turbo Assembler (TASM), Turbo Debugger (TD) on Ubuntu
Step 1
First we will install an windows emulator called dosbox.
sudo apt-get install dosbox
Step2
Download the packages for Turbo Assembler(tasm) Turbo Debugger(td). Create a directory for tasm in your home directory and extract files into that directory.If you are unable to extract type this in your terminal and try again
sudo apt-get install unrar
Step3
download this sample .asm file. Place the file in the tasm directory.
NOTE: You can use your own asm file instead
Step4
Open dosbox( generally found in games sublist ). Now you have to mount the virtual c drive.
mount c /home/<username> eg: /home/alse
Inside the 8086 Central Processor Unit (CPU)
A register is one of a small set of data holding places that are part of a computer processor. A register may hold a computer instruction, a storage address, or any kind of data (such as a bit sequence or individual characters). Some instructions specify registers as part of the instruction. For example, an instruction may specify that the contents of two defined registers be added together and then placed in a specified register. A register must be large enough to hold an instruction - for example, in a 32-bit instruction computer, a register must be 32 bits in length. In some computer designs, there are smaller registers - for example, half-registers - for shorter instructions. Depending on the processor design and language rules, registers may be numbered or have arbitrary names.
GENERAL PURPOSE REGISTERS
SEGMENT REGISTERS
SPECIAL PURPOSE REGISTERS
FLAGS REGISTERS
GENERAL PURPOSE REGISTERS
8086 CPU has 8 general purpose registers; each register has its own name:
AX - the accumulator register (divided into AH / AL):
Generates shortest machine code
Arithmetic, logic and data transfer
One number must be in AL or AX
Multiplication & Division
Input & Output
BX - the base address register (divided into BH / BL).
CX - the count register (divided into CH / CL):
Iterative code segments using the LOOP instruction
Repetitive operations on strings with the REP command
Count (in CL) of bits to shift and rotate
DX - the data register (divided into DH / DL):
DX:AX concatenated into 32-bit register for some MUL and DIV operations
Specifying ports in some IN and OUT operations
SI - source index register:
Can be used for pointer addressing of data
Used as source in some string processing instructions
Offset address relative to DS
DI - destination index register:
Can be used for pointer addressing of data
Used as destination in some string processing instructions
Offset address relative to ES
BP - base pointer:
Primarily used to access parameters passed via the stack
Offset address relative to SS
SP - stack pointer:
Always points to top item on the stack
Offset address relative to SS
Always points to word (byte at even address)
An empty stack will had SP = FFFEh
SEGMENT REGISTERS
CS - points at the segment containing the current program.
DS - generally points at segment where variables are defined.
ES - extra segment register, it's up to a coder to define its usage.
SS - points at the segment containing the stack.
Although it is possible to store any data in the segment registers, this is never a good idea. The segment registers have a very special purpose - pointing at accessible blocks of memory.
Segment registers work together with general purpose register to access any memory value. For example, if we would like to access memory at the physical address 12345h (hexadecimal), we should set the DS = 1230h and SI = 0045h. This is good, since this way we can access much more memory than with a single register that is limited to 16 bit values.
CPU makes a calculation of physical address by multiplying the segment register by 10h and adding general purpose register to it(1230h * 10h + 45h = 12345h):
The address formed with 2 registers is called an effective address.
By default, BX, SI and DI registers work with DS segment register;
BP and SP work with SS segment register.
Other general purpose registers cannot form an effective address!
Also, although BX can form an effective address, BH and BL cannot!
SPECIAL PURPOSE REGISTERS
IP - the instruction pointer:
Always points to next instruction to be executed
Offset address relative to CS
IP register always works together with CS segment register and it points to currently executing instruction.
FLAGS REGISTER
Flags Register - determines the current state of the processor.
Flags Register is modified automatically by CPU after mathematical operations, this allows to determine the type of the result, and to determine conditions to transfer control to other parts of the program.
Generally you cannot access these registers directly.
Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example, when you add bytes 255 + 1(result is not in range 0...255). When there is no overflow this flag is set to 0.
Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in result, and to 0 when there is odd number of one bits. Even if result is a word only 8 low bits are analyzed!
Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4 bits).
Zero Flag (ZF) - set to 1 when result is zero. For none zero result this flag is set to 0.
Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. Actually this flag take the value of the most significant bit.
Trap Flag (TF) - Used for on-chip debugging.
Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external devices.
Direction Flag (DF) - this flag is used by some instructions to process data chains, when this flag is set to 0 - the processing is done forward, when this flag is set to 1 the processing is done backward.
Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127).
-----------------------------------------------------------------------------------------------------------------------------------------------
Debug(Lab-1)
Working with Debug: -
Type debug on TASM DOS BOX , you will get the DEBUG prompt of a hyphen (-). DEBUG has loaded your program and is ready to run. The description of each instruction will assume this as a starting point
Register command
you type in an r with no parameters
O/P: -
AX=0000 BX=0000 CX=0446 DX=0000 SP=FFFE BP=0000 SI=0000 DI=0000
DS=6897 ES=6897 SS=6897 CS=6897 IP=0100 NV UP DI PL NZ NA PE NC
-rax:- It will display the content of ax register
-R AX R and AX register
AX 0000 Debug responds with register and contents
: 1234 : is the prompt for entering new contents. We respond 1234
- Debug is waiting for the next command.
Now after changing the value, output in register using r command
Now if we display the registers, we see the following:
AX=1234 BX=0000 CX=0446 DX=0000 SP=FFFE BP=0000 SI=0000 DI=0000
DS=6897 ES=6897 SS=6897 CS=6897 IP=0100 NV UP DI PL NZ NA PE NC
6897:0100 E96B01 JMP 026E
Dump command: - d is used for dump command
the Dump command is mostly used to display data and Displays the contents of a range of memory addresses.
With our program loaded, if we enter the Dump command, we will see this:
6897:0100 E9 6B 01 43 4C 4F 43 4B-2E 41 53 4D 43 6F 70 79 ik.CLOCK.ASMCopy
6897:0110 72 69 67 68 74 20 28 43-29 20 31 39 38 33 4A 65 right (C) 1983Je
6897:0120 72 72 79 20 44 2E 20 53-74 75 63 6B 6C 65 50 75 rry D. StucklePu
6897:0130 62 6C 69 63 20 64 6F 6D-61 69 6E 20 73 6F 66 74 blic domain soft
6897:0140 77 61 72 65 00 00 00 00-00 00 00 00 00 00 00 00 ware............
6897:0150 00 00 00 00 00 00 00 00-00 24 00 00 00 00 00 00 .........$......
6897:0160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
6897:0170 00 00 00 00 00 00 00 00-00 00 00 00 44 4F 53 20 ............DOS
Dump command is divided into three parts.
1. Left
we have the address of the first byte on the line. This is in the format Segment:Offset.
2. Next comes the hex data at that location
Debug will always start thesecond line at a 16 byte boundary; that is, if you entered D 109, you would get 7 bytes of information on the first line (109-10F), and the second line would start at 110. The last line of data would have the remaining 9 bytes of data, so 80h bytes are still displayed.
3. The third area is the ASCII representation of the data.
Only the standard ASCII character set is displayed. Special characters for the IBMPC are not displayed; rather periods (.) are shown in their place. This makes searching for plain text much easier to do.
Dump can be used to display up to 64K bytes of data, with one restriction:
It cannot cross a segment boundary. That is, D 0100 l f000 is valid (display DS:0100 to DS:F0FF), but D 9000 l 8000 is not (8000h +9000h = 11000h andcrosses a segment boundary).
Since 64K is 10000h and cannot fit into four hex characters, Dump uses 0000 to indicate 64K. To display a complete segment, enter D 0 l 0. This will display the total 64K segment. If, at any time you want to suspend the display of data, Cntl-NumLock
works as usual. If you want to terminate the display, Cntl-Break will stop itand return you to the DEBUG prompt.
Debug Example
-A 100
6897:0100 mov ax,600
6897:0103 mov cx,0
6897:0106 mov dx,184f
6897:0109 mov bh,07
6897:010B int 10
6897:010D int 20
6897:010F
LIST OF MASM PROGRAMS WITH SOLUTIONS
1. Write a program to print HELLO
.model small
.data
msg db 'HELLO$'
.code
.startup
mov ah,9
mov dx,offset msg
int 21h
mov ah,8
mov bh,0
int 10h
mov bl,bh
mov bh,ah
mov cx,0
mov dx,194fh
mov ah,6
mov al,0
int 10h
mov ah,2
mov bh,0
mov dx,0
int 10h
mov ah,9
mov dx,offset msg
int 21h
.exit
end
2.FOR ascii
.model tiny
.code
.startup
main1: mov ah,6
mov dl,0ffh
int 21h
je main1
cmp al,0dh
je main2
.if al>='a' && al<='f'
sub al,20h
.endif
mov dl,al
int 21h
jmp main1
main2: .exit
end
3.For printing two lines string.
.MODEL SMALL
.DATA
MES DB 13,10
mes1 db 14,10
BUF DB 256 DUP(?)
.CODE
.STARTUP
CLD
MOV AX,0B800H
MOV ES,AX
MOV DI,0
MOV CX,240*800
MOV AX,0720H
REP STOSW
MOV AX,DS
MOV ES,AX
CLD
MOV DI,OFFSET BUF
.WHILE AL!=00DH
JMP AGAIN1
AGAIN2:
MOV AH,1
INT 21H
STOSB
.ENDW
AGAIN1:
CMP AL,00DH
JNE AGAIN2
MOV BYTE PTR[DI-1],'$'
MOV DX,OFFSET MES
MOV AH,9
INT 21H
.EXIT
END
4.Program for printing the word ddddddddd
.MODEL SMALL
.DATA
MSG DB 13,10, 'ddddddddd$'
.CODE
SET MACRO
MOV BH,0
MOV AH,02H
MOV DH,12
MOV DL,40
INT 10H
INC DH
ENDM
.STARTUP
SET
MOV AL,'d'
MOV CX,10
MOV AH,09H
MOV BL,0ECH
MOV BH,0H
INT 10H
SET
.EXIT
END
5.To get the smallest element in an array
.model small
.data
array db 10h,20h,30h,40h,50h,60h,70h,80h,90h,99h
large db 0h
.code
.startup
mov si,offset array
mov al,large
mov cx,9
again :
.if al>byte ptr[si+1]
mov al,[si+1]
.endif
loop again
mov large,al
.exit
end
6.To convert upper case to lower case and vice versa and display the string
.model small
.data
mes db 13,10
buf db 256 dup(?)
.code
.startup
mov ax,dx
mov es,ax
cld
mov di,offset buf
.while al!=0dh
mov ah,1
int a21h
.if al>='a' && al<='z'
sub al,20h
.elseif al>='A' && al<='Z'
add al,20h
.endif
stosb
.endw
mov byte ptr[di-1],'$'
mov dx,offset mes
mov ah,9
int 21h
.exit
end
7.To count the number of zeroes in a block of elements
.model small
.data
array dw 30 dup(0)
.code
.startup
mov ax,0
mov bx,offset array
mov dx,0
mov si,0
mov cx,30
again :
cmp dx,[bx+si]
jz l1
jnz l2
loop again
l1 :
inc ax
inc si
l2 :
inc si
.exit
end
8.for printing strings.
.MODEL SMALL
.DATA
BUFFER DB 255 DUP(?)
MSG DB 13,10,'It is hot day today, can you guess the temperature: $'
MSGE DB 13,10,'THANK YOU FOR YOUR RESPONSE$'
.CODE
.STARTUP
CALL DISP
MOV BUFFER,255
MOV DX,OFFSET BUFFER
CALL ENTER
CALL DISP1
.EXIT
DISP PROC NEAR
MOV AH,9
MOV DX,OFFSET MSG
INT 21H
RET
DISP ENDP
ENTER PROC NEAR
MOV AH,0AH
INT 21H
RET
ENTER ENDP
DISP1 PROC NEAR
MOV AH,9
MOV DX,OFFSET MSGE
INT 21H
RET
DISP1 ENDP
END
9.for printing the word "HELLO"
.MODEL SMALL
.DATA
MSG DB 13,10, 'HELLO$'
.CODE
SET MACRO
MOV BH,0
MOV AH,02H
MOV DH,12
MOV DL,40
INT 10H
INC DH
ENDM
10. for printing the text in with COLOUR.
.STARTUP
SET
MOV AL,'o'
MOV CX,5
MOV AH,09H
MOV BL,0ECH
MOV BH,0H
INT 10H
SET
MOV AL,'L'
MOV CX,4
MOV AH,09H
MOV BL,0ECH
MOV BH,0H
INT 10H
SET
MOV AL,'L'
MOV CX,3
MOV AH,09H
MOV BL,0ECH
MOV BH,0H
INT 10H
SET
MOV AL,'e'
MOV CX,2
MOV AH,09H
MOV BL,0ECH
MOV BH,0H
INT 10H
SET
MOV AL,'H'
MOV CX,1
MOV AH,09H
MOV BL,0ECH
MOV BH,0H
INT 10H
SET
.EXIT
END
11.To find the power of a given number,where the base and the power are stored in symbolic memory locations called base and power
.MODEL SMALL
.DATA
POWER DB 2H
BASE DB 4H
.CODE
.STARTUP
MOV AL,BASE
MOV CL,POWER
AGAIN:
MUL AL
LOOP AGAIN
.EXIT
END
12.Write a program to perform the operation NUM1/NUM2 store the value of the rounded quotient in the ANS
.MODEL SMALL
.DATA
NUM1 DB 11H
NUM2 DB 7H
ANS DB 00H
.CODE
.STARTUP
MOV AL,NUM1
MOV CL,NUM2
DIV CL
MOV CL,AL
MOV AL,AH
MOV BL,2H
MUL BL
CMP NUM2,AL
JAE APPEND
APPEND:
INC CL
MOV ANS,CL
.EXIT
END
13.Write a program to movea string from one location to another in the same order.
.MODEL SMALL
.DATA
MSG DB "HELLO"
DATA DB 100 DUP(?)
NEW DW 5 DUP(?)
.CODE
.STARTUP
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,MSG
LEA DI,NEW
MOV CX,5
CLD
REP MOVSB
.EXIT
END
14.Write a program to move a string from one location to another in reverse order.
.MODEL SMALL
.DATA
TEST DB 'HELLO'
DATA DB 100 DUP(?)
NEW DB 5 DUP(0)
.CODE
.STARTUP
START:
MOV AL,DATA
MOV DS,AX
MOV ES,AX
LEA SI,TEST
LEA DI,NEW+5
INC SI
DEC DI
MOVSB
LOOP START
.EXIT
END
15) Write a program to perform ASCII addition of numbers 2 and 8?
.model tiny
.code
mov ax,0
mov al,0
mov ax,32h
mov al,38h
aaa
add ax,3030h
.exit
end
16) Write a program to perform ASCII division of numbers 56 & 8?
.model tiny
.code
mov bl,0
mov ax,0
mov bl,8
mov ax,0506h
aad
div bl
.exit
End
17) Write a program to multiply the number 4 five times without using MUL instruction?
.model tiny
.code
.startup
mov ax,4
mov bx,4
shl ax,1
shl ax,1
add ax,bx
.exit
end
18)Write a program to multiply the number 5 ten times without using MUL instruction?
.model tiny
.code
.startup
mov ax,5
shl ax,1
mov bx,ax
shl ax,1
shl ax,1
add ax,bx
.exit
end
19) WAP Dislay "Hello" on the monitor using procedure Display?
.model tiny
.code
.startup
mov bx,offset disp
mov dl,'H'
call bx
mov dl,'E'
call bx
mov dl,'L'
call bx
mov dl,'L'
call bx
mov dl,'O'
call bx
.exit
disp proc near
mov ah,2
int 21h
ret
disp endp
end
20. DISPLAY DDDD IN COLOR
.MODEL SMALL
.DATA
MSG DB 13,10, 'DDDDDD$'
.CODE
SET MACRO
MOV BH,0
MOV AH,02H
MOV DH,12
MOV DL,40
INT 10H
INC DH
ENDM
.STARTUP
SET
MOV AL,'D'
MOV CX,6
MOV AH,09H
MOV BL,0ECH
MOV BH,0H
INT 10H
SET
.EXIT
END
21. ACCEPTING NAME AND PRINT ON THE SCREEN
.MODEL SMALL
.DATA
BUFFER DB 255 DUP(?)
MSG DB 13,10,'Name: $'
.CODE
.STARTUP
CALL DISP
MOV BUFFER,255
MOV DX,OFFSET BUFFER
CALL ENTER
.EXIT
DISP PROC NEAR
MOV AH,9
MOV DX,OFFSET MSG
INT 21H
RET
DISP ENDP
ENTER PROC NEAR
MOV AH,0AH
INT 21H
RET
ENTER ENDP
END
22. TO FILL THE SCREEN WITH '!' SYMBOL
.MODEL TINY
.CODE
HOME MACRO
MOV AH,2
MOV BH,0
MOV DX,0
INT 10H
ENDM
.STARTUP
HOME
MOV CX,25*80
MOV AH,6
MOV DL,'!'
MAIN1:
INT 21H
LOOP MAIN1
HOME
.EXIT
END
23. Write a program to first position the cursor at (0,0) on the screen, and then to fill it with exclamation marks (!).
.MODEL TINY
.CODE
HOME MACRO
MOV AH,2
MOV BH,0
MOV DX,0
INT 10H
ENDM
.STARTUP
HOME
MOV CX,25*80
MOV AH,6
MOV DL,’!’
MAIN1:
INT 21H
LOOP MAIN1
HOME
.EXIT
END
24. Write a program to display the message ‘Name:’ on the screen and to take the name entered by you using the keyboard till the enter key is pressed. Use DOS function 0AH to input the string from the
keyboard.
.MODEL SMALL
.DATA
BUF DB 255 DUP (?)
MSG DB 13,10,’Name: $’
.CODE
.STARTUP
CALL DIPL
MOV BUF,255
MOV DX,OFFSET MSG
CALL INPT
.EXIT
DIPL PROC NEAR
MOV AH,9
MOV DX,OFFSET MSG
INT 21H
RET
DIPL ENDP
INPT PROC NEAR
MOV AH,0AH
INT 21H
RET
INPT ENDP
END
25.Write six D's in the center of the monitor,change the color combination for the characters use different combinations.
.model small
.data
msg db 13,10,'DDDDD$'
.code
set macro
move bh,0
mov ah,02h
mov dh,12
mov dl,40
int 10h
inc dh
endm
.startup
set
mov al,'d'
mov cx,5
mov ah,09h
mov bl,0ech
mov bh,0h
int 10h
.exit
end
26.OFfset
.model small
.data
lista db 30 dup(10)
listb db 30 dup(?)
.code
.startup
mov cx,30
mov si,offset lista
mov di,offset listb
begin:
mov di,si
inc si
inc di
loop begin
.exit
end
27.PROGRAM27
.data
list dw 50 dup(?)
.code
.startup
mov di,offset list
mov ax,0ffh
mov cx,50
again:
mov di,ax
inc di
loop again
.exit
end
28.PROGERAM 28
.MODEL SMALL
.CODE
.STARTUP
MOV AX,00
ADD AX,5
ADD AX,6
ADD AX,7
ADD AX,8
ADD AX,9
ADD AX,10
MOV CL,06
DIV CL
.EXIT
END
29.PROGRAM 29
.MODEL SMALL
.DATA
NUMB DB 4
NUMB1 DB 2
ANSQ DB 0
ANSR DB 0
.CODE
.STARTUP
MOV AL,NUMB
MOV AH,0
DIV NUMB1
MOV ANSQ,AL
MOV ANSR,AH
.EXIT
END
30.PROGRAM 30
.MODEL SMALL
.DATA
NUMB DB -4
NUMB1 DB 2
ANSQ DB 0
ANSR DB 0
.CODE
.STARTUP
MOV AL,NUMB
CBW
IDIV NUMB1
MOV ANSQ,AL
MOV ANSR,AH
.EXIT
END
31.To find the power of a given number where the base and the power are stored in a memory location called base and power
.model small
.data
power db 3
base db 5
.code
.startup
mov bl,base
mov al,base
mov cl,power
again: mul bl
loop again
.exit
end
----------------------------------------------------------------------
32.WAP to perform the operation num1/num2 store the value of the rounded quotient in ans
.MODEL SMALL
.DATA
NUM1 DW 10
NUM2 DB 3
ANS DB 0
.CODE
.STARTUP
MOV AX,NUM1
MOV BL,NUM2
DIV BL
ADD AH,AH
JB AGAIN
INC AL
AGAIN: MOV ANS,AL
.EXIT
END
----------------------------------------------------------------------
33) WAP TO MOVE A STRING FROM ONE LOCATION TO ANOTHER IN THE SAME ORDER
.MODEL SMALL
.DATA
TEST_MSG DB 'HELLO'
DATA DB 100 DUP(?)
NEWLOC DB 5 DUP(0)
.CODE
.STARTUP
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI, TEST_MSG
LEA DI, NEWLOC
MOV CX,5
CLD
REP MOVSB
.EXIT
END
----------------------------------------------------------------------
34) WAP TO MOVE A STRING FROM ONE LOCATION TO ANOTHER IN REVERSE ORDER
.MODEL SMALL
.DATA
TEST_MSG DB 'HELLO'
DATA DB 100 DUP(?)
NEWLOC DB 5 DUP(0)
.CODE
.STARTUP
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI, TEST_MSG
LEA DI, NEWLOC+5
MOV CX,5
INC SI
DEC DI
MOVSB
JMP START
.EXIT
END
35)WAP to count the number of occurances of 00 in a block of 20 elements.
.model small
.data
block dw 12,00,32,45,00,98,13,34,99,00,89,55,67,00,90,13,16,19,20,00
.code
.startup
lea si,block
mov dx,0
mov cx,20
start:
.if [si]==0
inc dx
.endif
inc si
loop start
.exit
end
_______________________________________________________________________
36)WAP to reverse the contents of an array by using a stack.The data should be allotted in the memory itself.
.model small
.data
array dw 1,2,3,4,5,6,7,8,9,10
.code
.startup
lea si,array
lea di,array
mov cx,10
start:
push [si]
inc si
loop start
mov cx,10
next:
pop bx
mov [di],bx
inc di
loop next
.exit
end
________________________________________________________________________
37)Write a program to count the number of 0's and 1's in the binary representation of a number.
.model tiny
.code
.startup
mov al,8
mov bl,0
mov cx,8
mov dl,0
again:
shr al
jc top
jnc bot
loop again
top:inc bl
bot:inc dl
mov cl,bl
mov al,dl
.exit
end
_________________________________________________________________________
38. Program 38
MACRO PROGRAMS
.MODEL SMALL
.DATA
BUF DB 255 DUP (?)
MSG DB 3,10,'Name: $'
.CODE
.STARTUP
CALL DIPL
MOV BUF,255
MOV DX,OFFSET MSG
CALL INPT
.EXIT
DIPL PROC NEAR
MOV AH,9
MOV DX,OFFSET MSG
INT 21H
RET
DIPL ENDP
INPT PROC NEAR
MOV AH,0AH
INT 21H
RET
INPT ENDP
END
39.Write a program to get the largest element in an array of 10 elements and to store the result in the variable LARGE.
.MODEL SMALL
.DATA
LIST1 DB 10 DUP (?)
.CODE
.STARTUP
MOV DI, OFFSET LIST1
MOV [DI], 01
MOV [DI + 1], 01
MOV [DI + 2], 01
MOV [DI + 3], 01
MOV [DI + 4], 01
MOV [DI + 5], 02
MOV [DI + 6], 01
MOV [DI + 7], 01
MOV [DI + 8], 01
MOV [DI + 9], 01
MOV AX,0000H
MOV AL, [DI]
MOV BX,00
MOV CX,10
JUMPMORE:
CMP AL,[DI]
INC DI
JL JUMPMORE
MOV AL,[DI]
DEC CX
LOOP JUMPMORE
MOV BL, AL
.EXIT
END
40.Write a program to change the case of the given word
i.e.
if the word is given in upper case convert it to lower case or
if the word is in lower case than convert it to upper case.
Make use of DOS interrupts to read and write the characters.
Enter will mark the end of the input,Enter has a ASCII code of 0DH.
.MODEL TINY
.CODE
.STARTUP
MAIN1:
MOV AH,6
MOV DL,0FFH
INT 21H
JE MAIN1
CMP AL,3
JE MAIN2
IF AL>='A' && AL<='2'
SUB AL,20H
END IF
MOV DL,AL
INT 21H
JMP MAIN1
MAIN2:
.EXIT
END
41.Write a program which counts the number of zeros that occurs ina block of elments.
.MODEL SMALL
.CODE
.STARTUP
MOV CX,30H
MOV AL,0H
MOV BX,100H
MOV DX,0H
COMP:
INC BX
CMP [BX],AL
JZ INCR
LOOP COMP
JMP GO
INCR:
INC DX
LOOP COMP
GO:
.EXIT
END
.model small
.data
msg db 'name$'
.code
.startup
mov ah,9
mov dx,offset msg
int 21h
mov ah,8
mov bh,0
int 10h
mov bl,bh
mov bh,ah
mov cx,0
mov dx,194fh
mov ah,6
mov al,0
int 10h
mov ah,2
mov bh,0
mov dx,0
int 10h
mov ah,9
mov dx,offset msg
int 21h
.exit
end
MODEL SMALL
.DATA
ARRAY DB 10 DUP (?)
.CODE
MOV SI,OFFSET ARRAY
MOV BL,0
MOV AL,2
MOV DX,3
MOV CX,10
OPP: MUL BL
MOV DI,AX
MOV AL,2
ADD DI,DX
MOV [SI],DI
INC BL
INC SI
LOOP OPP
.EXIT
END
42. Program 42
.MODEL SMALL
.CODE
DISP PROC NEAR
MOV AH,02H
INT 21H
RET
DISP ENDP
.STARTUP
MOV AH,02H
MOV BH,0
MOV DH,11
MOV DL,39
INT 10H
MOV DL,'S'
CALL DISP
MOV DL,'H'
CALL DISP
MOV DL,'O'
CALL DISP
MOV DL,'A'
CALL DISP
MOV DL,'I'
CALL DISP
MOV DL,'B'
CALL DISP
.EXIT
END
43.Program to clear scree and printing character.
.MODEL SMALL
.DATA
MES DB 13,10
BUF DB 256 DUP(?)
.CODE
.STARTUP
CLD
MOV AX,0B800H
MOV ES,AX
MOV DI,0
MOV CX,240*800
MOV AX,0720H
REP STOSW
MOV AX,DS
MOV ES,AX
CLD
MOV DI,OFFSET BUF
.WHILE AL!=00DH
JMP AGAIN1
AGAIN2:
MOV AH,1
INT 21H
STOSB
.ENDW
AGAIN1:
CMP AL,00DH
JNE AGAIN2
MOV BYTE PTR[DI-1],'$'
MOV DX,OFFSET MES
MOV AH,9
INT 21H
.EXIT
END
44. Wrie an assembly program to creates a file and write a string to it.
; This program creates a file and writes a string to it
.MODEL small
.DATA
filename db "file.txt",0
string db "Hello RK"
handle dw 0
.CODE
.STARTUP
mov ah,3ch ; create file
mov cx,01h
lea dx,filename
int 21h
jc error
mov handle,ax
; write string to file
mov ah,40h
mov bx,handle
mov cx,08h
lea dx,string
int 21h
jc error
mov ah,3eh ; close file
mov bx,handle
int 21h
error: ; terminate program
mov ax,4c00h
int 21h
end
45. Write an assembly program to open a file, reads from it .
; This program opens a file, reads from it
;First you create file in your TASM Folder and write some value to display it.
.MODEL small
.DATA
filename db 'file.txt',0 ;File should be availble before reading it
string db 8 dup(0)
endchar db '$' ; used when displaying the string
handle dw 0
.CODE
.STARTUP
mov ax,3d02h ; open file -Function
lea dx,filename
int 21h
jc error
mov handle,ax
mov ah,3fh ; read from file
mov bx,handle
mov cx,8
lea dx,string
int 21h
jc error
mov ah,3eh ; close file
mov bx,handle
int 21h
mov ah,09h ; display string
lea dx,string
int 21h
xor ax,ax ; wait for keystroke
int 16h
error: ; terminate program
mov ax,4c00h
int 21h
end
46. Write an assembly program to display the system time.
;program to display the system time.
.MODEL SMALL
.STACK 100H
.DATA
PROMPT DB 'Current System Time is : $'
TIME DB '00:00:00$' ; time format hr:min:sec
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
LEA BX, TIME ; BX=offset address of string TIME
CALL GET_TIME ; call the procedure GET_TIME
LEA DX, PROMPT ; DX=offset address of string PROMPT
MOV AH, 09H ; print the string PROMPT
INT 21H
LEA DX, TIME ; DX=offset address of string TIME
MOV AH, 09H ; print the string TIME
INT 21H
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
;**************************************************************************;
;**************************************************************************;
;------------------------- Procedure Definitions ------------------------;
;**************************************************************************;
;**************************************************************************;
;**************************************************************************;
;------------------------------ GET_TIME --------------------------------;
;**************************************************************************;
GET_TIME PROC
; this procedure will get the current system time
; input : BX=offset address of the string TIME
; output : BX=current time
PUSH AX ; PUSH AX onto the STACK
PUSH CX ; PUSH CX onto the STACK
MOV AH, 2CH ; get the current system time
INT 21H
MOV AL, CH ; set AL=CH , CH=hours
CALL CONVERT ; call the procedure CONVERT
MOV [BX], AX ; set [BX]=hr , [BX] is pointing to hr
; in the string TIME
MOV AL, CL ; set AL=CL , CL=minutes
CALL CONVERT ; call the procedure CONVERT
MOV [BX+3], AX ; set [BX+3]=min , [BX] is pointing to min
; in the string TIME
MOV AL, DH ; set AL=DH , DH=seconds
CALL CONVERT ; call the procedure CONVERT
MOV [BX+6], AX ; set [BX+6]=min , [BX] is pointing to sec
; in the string TIME
POP CX ; POP a value from STACK into CX
POP AX ; POP a value from STACK into AX
RET ; return control to the calling procedure
GET_TIME ENDP ; end of procedure GET_TIME
;**************************************************************************;
;------------------------------- CONVERT --------------------------------;
;**************************************************************************;
CONVERT PROC
; this procedure will convert the given binary code into ASCII code
; input : AL=binary code
; output : AX=ASCII code
PUSH DX ; PUSH DX onto the STACK
MOV AH, 0 ; set AH=0
MOV DL, 10 ; set DL=10
DIV DL ; set AX=AX/DL
OR AX, 3030H ; convert the binary code in AX into ASCII
POP DX ; POP a value from STACK into DX
RET ; return control to the calling procedure
CONVERT ENDP ; end of procedure CONVERT
;**************************************************************************;
;--------------------------------------------------------------------------;
;**************************************************************************;
END MAIN
47. Write a program draws a pixel on the screen at location (240, 320) using the “write pixel”
function (AH=0Ch) of INT 10h.
.MODEL SMALL ; this defines the memory model
.STACK 100 ; define a stack segment of 100 bytes
.DATA ; this is the data segment
.CODE ; this is the code segment
MOV AX,@DATA ; get the address of the data segment
MOV DS, AX ; and store it in DS register
MOV AH, 00h ; set video mode
MOV AL, 12h ; graphics 640x480
INT 10h
; draw a green color pixel at location (240, 320)
MOV AH, 0Ch ; Function 0Ch: Write pixel dot
MOV AL, 02 ; specify green color
MOV CX, 320 ; column 320
MOV DX, 240 ; row 240
MOV BH, 0 ; page 0
INT 10h
MOV AH, 07h ; wait for key press to exit program
INT 21h
MOV AX, 4C00H ; Exit to DOS function
INT 21H
END
48. Write program draws a horizontal line on the screen from location (240, 170) to (240,470)
by writing pixels on the screen using function (AH=0Ch) of INT 10h.
MODEL SMALL ; this defines the memory model
.STACK 100 ; define a stack segment of 100 bytes
.DATA ; this is the data segment
.CODE ; this is the code segment
MOV AX,@DATA ; get the address of the data segment
MOV DS, AX ; and store it in DS register
MOV AH, 00h ; set video mode
MOV AL, 12h ; graphics 640x480
INT 10h
; draw a green color line from (240, 170) to (240, 470)
MOV CX, 170 ; start from row 170
MOV DX, 240 ; and column 240
MOV AX, 0C02h ; AH=0Ch and AL = pixel color (green)
BACK: INT 10h ; draw pixel
INC CX ; go to next column
CMP CX, 470 ; check if column=470
JB BACK ; if not reached column=470, then continue
MOV AH, 07h ; wait for key press to exit program
INT 21h
MOV AX, 4C00H ; Exit to DOS function
INT 21H
END ; end of the program