28
150701: Advance Processors LAB MANUAL 1

Advance Processors Lab Manual

Embed Size (px)

DESCRIPTION

lab manual for advance processor

Citation preview

Page 1: Advance Processors Lab Manual

150701: Advance Processors

LAB MANUAL

1

Page 2: Advance Processors Lab Manual

INDEX

Sr.No.

AIM PageNo.

1 Introduction to Debug Commands. 3

2 To perform addition & subtraction of an array of 16-bit nos. 5

3 To perform conversion of a number from (A) HEX to BCD (B) BCD to HEX. 7

4 To perform sorting operation on an array of 16-bit nos. 9

5 To perform Addition and Multiplication on 32-bit Nos. 11

6 Introduction to Modular Programming and Procedures. 13

7 To perform string related operations. 15

8 To perform Keyboard and Video operations using DOS and BIOS interrupts. 17

9 To perform Mouse Operations using software interrupts. 20

10 To perform Graphics mode access using DOS & BIOS interrupts. 21

11 To perform Serial communications using INT 14h. 23

2

Page 3: Advance Processors Lab Manual

PRACTICAL - 1

Aim: Introduction to Debug Commands

Description:

Debug is a tool with the help of which programmer can find out bugs present in the program. To facilitate with debugging task, debug program allows several commands with the help of which programmer can verify the proper execution of program. Following are the commands offered by debug.

C:>debug-If we execute debug.exe program, it will show hypen (command prompt for debug) ‘-‘. At this command prompt user has to give one of the following commands.

(1) –r

With the help of ‘r’ command user can see the contents of internal registers like AX,BX,CX,DX,CS,DS,ES,SS,SP,BP,SI,DI,IP,Flag register.

(2) –r register

In the above option user can modify the register by giving the name of the register with r command. For e.g -r ip. –r ipip 0100: After : give the new value of regiter.

(3) –d

With the help of ‘d’ command user can see the contents of memory locations. d is to be followed by segment register:offset. For e.g d ds:1000h.

1257:1000 34 5a 5b 39 5e 32 10 07 8c 3d 34 55 60 15 7c 6f 4 …………………1257:1010………………………………………………………………………………1257:1020………………………………………………………………………………

(4) –e

With the help of ‘e’ command user can edit any memory location. For example –e ds:0116e:0000 34.45

– 34 can be replaced with 45.

3

Page 4: Advance Processors Lab Manual

(5) –t

With the help of ‘t’ command user can single step the programm. At a time one line of program will be executed and then the contents of internal register will be shown on the screen by debug. This way user can verify the logical sequence of the program.

(6) –g

With the help of ‘g’ command (go command) user can execute the program in normal flow. Program will go on executing until the termination is achieved in the program.

(7) –u

With the help of ‘u’ command ( unassamble command) user can unassamble the exe file of the program. This way user can verify whether the program is properly being point by debug tool or not.

(8) debug filename.exe

Above is the way with which user can supply exe file to the debug. Then onwards above commands can be used to verify the logical sequence of the program.

Program Execution Steps

Use assembler file ‘masm’ to convert filename.asm in to filename.obj. Use linker file ‘link’ to convert filename.obj in to filename.exe in following manner.

1) C:>masm filename.asmGo on clicking ‘Enter’ key until you get the command prompt on screen

2) C:>link filename.objGo on clicking ‘Enter’ key until you get the command prompt on screen

3) C:>debug filename.exeYou will find a hyphen ‘-‘on the screen.

4) Using ‘-U’ unassemble command, check whether the program you have entered is available in the memory or not?

5) Use the above mentioned debug commands to find any errors in the program using single stepping.

4

Page 5: Advance Processors Lab Manual

PRACTICAL - 2

Aim: To perform addition & subtraction of an array of 16-bit nos.

A) ADDITION.model small.data

a dw 2020h,3454h,5365h,8765h ;assign arrayb dw 4521h,5436h,8765h,9876h c 2 dup(0)

.codemov ax,@data mov ds,axlea si,alea di,blea bx,cmov cx,04h ;set counter for arrayagain:mov ax,[si]add ax,[di] ;add 2 no.mov [bx],ax ;storing ansinc siinc siinc diinc diinc bxinc bxloop againint 3hend

B) SUBTRACTION.model small.data

a dw 2020h,3454h,5365h,8765h ;assign arrayb dw 4521h,5436h,8765h,9876hc 2 dup(0)

.codemov ax,@datamov ds,axlea si,alea di,blea bx,cmov cx,04h ;set counteragain:mov ax,[si]

5

Page 6: Advance Processors Lab Manual

sub ax,[di] ;subtract two numbersmov [bx],ax ;store ansinc siinc siinc diinc diinc bxinc bxloop againint 3hend

6

Page 7: Advance Processors Lab Manual

PRACTICAL - 3

AIM: To perform conversion of a number from (A) HEX to BCD (B) BCD to HEX.

A) 16-bit HEX to BCD conversion

.model small

.dataa dw 0123h ;assign hexans dw 4 dup(0)

.codemov ax,@datamov ds,axles di,ansmov ax,[si]mov bx,03e8h ;seperating 1st digitdiv bxmov [di],axinc di inc dimov as,dxmov bl,64h ;seperate 2nd digitdiv blmov ch,ahmov ax,0000hmov al,chinc diinc dimov bl,0ah ;separate 3rd digitdiv blmov [di],alinc di inc dimov [di],al ;storing ansint 3hend

B) Four digit BCD to HEX conversion

.model small

.dataa db 9,9,9,9 ;assign bcd nob dw 0.code

mov ax,@datamov ds,ax

7

Page 8: Advance Processors Lab Manual

lea si,alea di,bmov ax,0000hmov bx,03e8h ;set bx for X1000 mov al,[si] mul bxadd [di],axinc simov ax,000hmov bx,0064h ;set bx for x100 mov al,[si]mul bxadd [di],axinc simov ax,0000hmov bx,000ah ;set bx for x10mov al,[si]mul bxadd [di],axinc simov ax,000hmov al,[si]mul bxadd [di],ax ;store ans in diint 3hend

8

Page 9: Advance Processors Lab Manual

PRACTICAL - 4

AIM: To perform sorting operation on an array of 16-bit nos.

A) Sorting of a number in Ascending order

.model small

.dataa dw 1234h,1000h,3000h,2222h,0900h ;assign array

.codemov ax,@datamov ds,axmov dx,04h ;set count1again2:mov cx,04h ;set count2lea si,aagain1:mov ax,[si]cmp ax,[si+2] ;comparingjb nextxchg ax,[si+2] ;exchanging valuesxchg ax,[si]next:inc siinc siloop again1dec dxjnz again2int 3hend

B) Sorting of a number in Descending order

.model small

.dataa dw 1234h,1000h,3000h,2222h,0900h ;assigning array

.codemov ax,@datamov ds,axmov dx,04h ;set first countagain2:mov cx,04h ;set second countlea si,aagain1:mov ax,[si]cmp ax,[si+2]

9

Page 10: Advance Processors Lab Manual

ja nextxchg ax,[si+2] ;exchanging valuesxchg ax,[si]next:inc siinc siloop again1dec dxjnz again2int 3hend

10

Page 11: Advance Processors Lab Manual

PRACTICAL - 5

AIM: To perform Addition and Multiplication on 32-bit Nos.

A) ADDITION OF 32-BIT NOs

.model small

.dataa dw 1000h,2000h,3000h,4000h ;assigning the arrayb dw 3 dup(0)

.codemov ax,@datamov ds,axlea si,alea di,bmov al,[si+3]mov bl,[si+7]mov ah,[si+2]mov bh,[si+6]add ax,bx ;adding the last bytes of two no.

mov [di+5],almov [di+4],ah

mov al,[si+1]mov ah,[si]mov bl,[si+5]mov bh,[si+4]adc ax,bx ;adding the first bytes of two no. with carry

mov [di+3],almov [di+2],ah

mov bx,0000hmov ax,0000hadc ax,bx ;adding the carry generated by the first bytes of two no.mov [di+1],alint 3hend

B) 32-BIT MULTIPLICATION

.model small

.dataa dw 0000h,0001h,0000h,0007h ;assigning the arrayb dw 4 dup(0)

11

Page 12: Advance Processors Lab Manual

.codemov ax,@datamov ds,axlea si,alea di,bmov al,[si+3]mov ah,[si+2]mov bl,[si+7]mov bh,[si+6]mul bx ;multiplying the last bytes of 2 no.mov [di+7],almov [di+6],ahmov [di+5],dlmov [di+4],dhmov cx,dxmov al,[si+1]mov ah,[si]mul bx ;multiplying the last and first byte of 2nd and 1st no.mov [di+3],dlmov [di+2],dhadc ax,cxmov cx,axmov al,[si+5]mov ah,[si+4]mov bl,[si+3]mov bh,[si+2]mul bx ;multiplying the last and first byte of 1st and 2nd no.adc ax,cxmov [di+5],almov [di+4],ahmov cl,[di+3]mov ch,[di+2]mov ax,cxadc ax,dxmov cx,axmov al,[si+1]mov ah,[si]mov bl,[si+5]mov bh,[si+4]mul bx ;multiplying the first byte of the two no.adc ax,cxmov [di+3],almov [di+2],ahmov [di+1],dlmov [di],dhint 3hend

12

Page 13: Advance Processors Lab Manual

PRACTICAL - 6

Aim: Introduction to Modular Programming and Procedures.

Explanation:

User can create multiple assembly files and link them using Linker. The variables defined in one module can be accessed by another module. Same way procedures defined in one module can be called by another module.

Let us say we have two files defined as a1.asm and a2.asm. In a1.asm we are defining one variable called ‘sum’ with db(define byte) type. If this variable is to be used in another module called a2.asm then ‘sum’ should be declared as ‘public’ in a1.asm and ‘extrn’ in a2.asm.C:>masm a1.asmC:>link a1.obj

C:>masm a2.asmC:>link a1.obj + a2.obj

In the link both the object files should be specified. The exe file will be created with the name given for first object file in link command. In above case a1.exe will be generated by linker.

a1.asm

.model small

public sum byteextrn summation far

.datasum db 35hans db ?

.codemov ax,@datamov ds,axcall summationint 3end

a2.asm

.model smallextrn sum byte, ans bytepublic summation .codesummation proc far

13

Page 14: Advance Processors Lab Manual

mov al,sumadd bh,almov ans,bh

summation endpend

In the above program sum and ans these two variables are defined with ‘public’ in a1.asm and with ‘extrn’ in a2.asm. Same way procedure summation defined in a2.asm module is called in a1.asm module using ‘extrn’ and ‘public’ assembler directives. In this way programmer can create a main file which will call other subroutines defined in other ‘.asm’ files.

14

Page 15: Advance Processors Lab Manual

PRACTICAL - 7

AIM: To perform string related operations.

(A) Find the number of occurrence for any character in the given string.

.model small

.data a db 'akajahsgdfdhajks' ;assigning string b db 'a' ;giving char..code mov ax,@data mov ds,ax lea si,a lea di,b mov dl,00h mov cl,10h ;assigning length of string mov bl,[di]again: mov al,[si] cmp al,bl ;comparing each char. jne next inc dl ;storing count of charnext: inc si loop again int 3h end

(B) Convert a string from lower case to upper case.

.model small

.data a db 'Aksnishkarabhani' ;assingning string .code mov ax,@data mov ds,ax lea si,a mov cl,10h ;set count of string mov bl,60h ;set bx for compareagain: mov al,[si] cmp al,bl ;comparing with lower case jb next mov dl,20h sub al,dl ;converting lower in to upper

15

Page 16: Advance Processors Lab Manual

mov [si],alnext: inc si loop again int 3h end

(C) Convert a string from Upper case to lower case.

.model small

.data a db 'AKAKAJSHSGDYDBCV' :assigning string.code mov ax,@data mov ds,ax lea si,a mov cl,10h ;set count for string mov bl,60h ;set bx for compareagain: mov al,[si] cmp al,bl ;compare upper with lower case ja next mov dl,20h add al,dl ;converting in to lower case mov [si],alnext: inc si loop again int 3h end

D) Copy a string from one location to another location.

.model small

.data a db 'akash' ;assigning string b db 7 dup(0).code cld mov ax,@data mov ds,ax mov es,ax lea si,a lea di,b mov cl,05h rep movsb ;repeating till all char move to extra segment int 3h

end

16

Page 17: Advance Processors Lab Manual

PRACTICAL - 8

Aim: To perform Keyboard and Video operations using DOS and BIOS interrupts.(1) Keyboard reading using DOS interrupt INT 21H and BIOS interrupt INT 16H(2) Video System routines using INT 10h

Explanation:

When we hit a key hardware interrupt int 09h is generated and scan code of the key being pressed will be read from key board by the system. This scan code is stored in BIOS data area by the system. With the help of DOS int 21h and BIOS int 16h we can read this scan code and judge about the key being pressed. The port address of key board is 60h.

(1) Accepting character using DOS int 21h

.model small

.dataa label bytemax db 20 ;Maximum charaters to be readactual db ? ;Actual characters to be readkeys db 20 dup (‘ ‘) ;Characters will be stored here

.codemov ah,0ah ;request keyboard input

lea dx,a ;load address of parameter listint 21h ;call interrupt service

int 3end

(a) mov ah,01h ;Request key board input with echoint 21hAl register will contain the ASCII code of the key being pressed.

(b)mov ah,07h ;Request key board input without echoint 21hEntered character will not be having echo on screen. Al will contain the ASCII code of the key being pressed.

(2) Key Board entry using BIOS int 16h

17

Page 18: Advance Processors Lab Manual

(a) mov ah,0h ;Request key boardint 16h

Task: Writedown a program to read 10 characters string from key board. Store it in memory and compare with another string stored with name “password”.

VIDEO SYSTEM ROUTINES

(1) Set Video ModeMov ah,00hMov al,03h ;Standard Colour text modeInt 10h

(2) Set Cursor SizeMov ah,01hMov ch,00h ;Start Scan lineMov cl,14h ;End Scan lineInt 10h

(3) Set Cursor Position

Mov ah,02h

Mov bh,0h ;Page 0Mov dh,12h ;Row 12Mov dl,30h ;Column 30Int 10h

(4) Select Active Page

Mov ah, 05h

Mov al,page ;page = 0,1,2 or 3Int 10h

(5) Scroll up screen

Mov ax,601h ;Request scroll up one line

Mov bh,61h ;Brown back ground , blue foregroundMov cx,0000h ;From 00 : 00Mov dx,184fh ;24 : 79 Full screenint 10h

(6) Display a character a cursor positionMov ah,0ahMov al,char

18

Page 19: Advance Processors Lab Manual

Mov bh,page no.Mov cx,repetition ;How many times character to be ;displayedInt 10h

(7) Display character and attribute at cursor

mov ah,09hmov al,01hmov bh,0mov bl,16h ;Blue = Back ground, Brown = Foregroundmov cx,60int 10h

(7) Display a string terminated with dollar ($) sign

Mov ah,09hLea dx,stringInt 21h

19

Page 20: Advance Processors Lab Manual

PRACTICAL – 9

Aim: To perform Mouse Operations using software interrupts.

Explanation:

(1) Initialize mouse

Mov ax, 0h

Int 33h(2) Display Mouse pointer

Mov ax, 01h

Int 33h(3) Conceal the mouse pointer

Mov ax, 02hInt 33h

(4) Get Button status and pointer locationMov ax, 03hInt 33hAbove routine will return BX = Status of buttonBit 0 of BX = Left Button ( 0 = up , 1 = pressed down)Bit 1 of BX = Right Button ( 0 = up , 1 = pressed down)Bit 2 of BX = Centre Button ( 0 = up , 1 = pressed down)Bits 3 –15 reserved for internal use

CX = Horizontal Co-ordinatesDX = Vertical Co-ordinates

(5) Set pointer location

Mov ax,04h

Mov cx,horizontalMov dx,vertical Int 33h

Task:Show the mouseClick mouse and get button status informationClick mouse and get the pointer location

20

Page 21: Advance Processors Lab Manual

PRACTICAL - 10

Aim: To perform Graphics mode access using DOS & BIOS interrupts.

Explanation:

(1) Set video mode

Mov ah,0h

Mov al,03h ;Standard color textInt 10h

(2) Set cursor size

Mov ah,01h

Mov ch,0 ;Start scan lineMov cl,14 ;end scan lineInt 10h

(3) Set color palette

(i) Select background color

Mov ah,0bh

Mov bh,0 ;Select Background colorMov bl,04 ;color redInt 10h

(ii) select paletter for graphics, where bl contains the palette ( 0 or 1 )

mov ah,0bhmov bh,01hmov bl,0 ;number 0 (green,red,brown)int 10h

(4) Write pixel dot

Mov ah,0ch

Mov al,03Mov bh,0 ;Page no.Mov cx,200 ;columnMov dx,500 ;rowInt 10h

(5) Read pixel dot

Mov ah,0dh

21

Page 22: Advance Processors Lab Manual

Mov bh,0 ;page no.Mov cx,80 ;columnMov dx,110 ;rowInt 10h

22

Page 23: Advance Processors Lab Manual

PRACTICAL - 11

Aim: To perform Serial communications using INT 14h.

Explanation:

Int 14h supports 4 functions to implement Serial communications

(1) Initialize communication port

Mov ah,00hMov al,11100011b ;Line parametersMov dx,0 ;Com1 serial portInt 14h

(2) Transmit character

Mov ah,01hMov al,34h ;Ascii value of character to be ;transmittedMov dx,0Int 14h

(3) Receive character

Mov ah,02hMov dx,0Int 14h;Al contains the character received

(4) Return status of communications port

Mov ah,03hMov dx,0Int 14h

Ah, and al contain the line status and modem status respectively.

23