Anda di halaman 1dari 23

150701: Advance Processors LAB MANUAL

INDEX
Sr. No. 1 2 3 4 5 6 7 8 9 10 11 Introduction to Debug Commands. To perform addition & subtraction of an array of 16-bit nos. To perform conversion of a number from (A) HEX to BCD (B) BCD to HEX. To perform sorting operation on an array of 16-bit nos. To perform Addition and Multiplication on 32-bit Nos. Introduction to Modular Programming and Procedures. To perform string related operations. To perform Keyboard and Video operations using DOS and BIOS interrupts. To perform Mouse Operations using software interrupts. To perform Graphics mode access using DOS & BIOS interrupts. To perform Serial communications using INT 14h. AIM Page No. 3 5 7 9 11 13 15 17 20 21 23

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 ip ip 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:0 116e:0000 34.45 34 can be replaced with 45.

(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) 2) 3) C:>masm filename.asm Go on clicking Enter key until you get the command prompt on screen C:>link filename.obj Go on clicking Enter key until you get the command prompt on screen C:>debug filename.exe You 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.

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 array b dw 4521h,5436h,8765h,9876h c 2 dup(0) .code mov ax,@data mov ds,ax lea si,a lea di,b lea bx,c mov cx,04h ;set counter for array again: mov ax,[si] add ax,[di] ;add 2 no. mov [bx],ax ;storing ans inc si inc si inc di inc di inc bx inc bx loop again int 3h end B) SUBTRACTION .model small .data a dw 2020h,3454h,5365h,8765h ;assign array b dw 4521h,5436h,8765h,9876h c 2 dup(0) .code mov ax,@data mov ds,ax lea si,a lea di,b lea bx,c mov cx,04h ;set counter again: mov ax,[si] 5

sub ax,[di] mov [bx],ax inc si inc si inc di inc di inc bx inc bx loop again int 3h end

;subtract two numbers ;store ans

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 .data a dw 0123h ans dw 4 dup(0) .code mov ax,@data mov ds,ax les di,ans mov ax,[si] mov bx,03e8h div bx mov [di],ax inc di inc di mov as,dx mov bl,64h div bl mov ch,ah mov ax,0000h mov al,ch inc di inc di mov bl,0ah div bl mov [di],al inc di inc di mov [di],al int 3h end

;assign hex

;seperating 1st digit

;seperate 2nd digit

;separate 3rd digit

;storing ans

B) Four digit BCD to HEX conversion .model small .data a db 9,9,9,9 ;assign bcd no b dw 0 .code mov ax,@data mov ds,ax 7

lea si,a lea di,b mov ax,0000h mov bx,03e8h ;set bx for X1000 mov al,[si] mul bx add [di],ax inc si mov ax,000h mov bx,0064h ;set bx for x100 mov al,[si] mul bx add [di],ax inc si mov ax,0000h mov bx,000ah ;set bx for x10 mov al,[si] mul bx add [di],ax inc si mov ax,000h mov al,[si] mul bx add [di],ax ;store ans in di int 3h end

PRACTICAL - 4
AIM: To perform sorting operation on an array of 16-bit nos. A) Sorting of a number in Ascending order .model small .data a dw 1234h,1000h,3000h,2222h,0900h ;assign array .code mov ax,@data mov ds,ax mov dx,04h ;set count1 again2: mov cx,04h ;set count2 lea si,a again1: mov ax,[si] cmp ax,[si+2] ;comparing jb next xchg ax,[si+2] ;exchanging values xchg ax,[si] next: inc si inc si loop again1 dec dx jnz again2 int 3h end B) Sorting of a number in Descending order .model small .data a dw 1234h,1000h,3000h,2222h,0900h ;assigning array .code mov ax,@data mov ds,ax mov dx,04h ;set first count again2: mov cx,04h ;set second count lea si,a again1: mov ax,[si] cmp ax,[si+2] 9

ja next xchg ax,[si+2] xchg ax,[si] next: inc si inc si loop again1 dec dx jnz again2 int 3h end

;exchanging values

10

PRACTICAL - 5
AIM: To perform Addition and Multiplication on 32-bit Nos. A) ADDITION OF 32-BIT NOs .model small .data a dw 1000h,2000h,3000h,4000h ;assigning the array b dw 3 dup(0) .code mov ax,@data mov ds,ax lea si,a lea di,b mov 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],al mov [di+4],ah mov al,[si+1] mov ah,[si] mov bl,[si+5] mov bh,[si+4] adc ax,bx mov [di+3],al mov [di+2],ah mov bx,0000h mov ax,0000h adc ax,bx mov [di+1],al int 3h end B) 32-BIT MULTIPLICATION .model small .data a dw 0000h,0001h,0000h,0007h b dw 4 dup(0)

;adding the first bytes of two no. with carry

;adding the carry generated by the first bytes of two no.

;assigning the array

11

.code mov ax,@data mov ds,ax lea si,a lea di,b mov al,[si+3] mov ah,[si+2] mov bl,[si+7] mov bh,[si+6] mul bx mov [di+7],al mov [di+6],ah mov [di+5],dl mov [di+4],dh mov cx,dx mov al,[si+1] mov ah,[si] mul bx mov [di+3],dl mov [di+2],dh adc ax,cx mov cx,ax mov al,[si+5] mov ah,[si+4] mov bl,[si+3] mov bh,[si+2] mul bx adc ax,cx mov [di+5],al mov [di+4],ah mov cl,[di+3] mov ch,[di+2] mov ax,cx adc ax,dx mov cx,ax mov al,[si+1] mov ah,[si] mov bl,[si+5] mov bh,[si+4] mul bx adc ax,cx mov [di+3],al mov [di+2],ah mov [di+1],dl mov [di],dh int 3h end

;multiplying the last bytes of 2 no.

;multiplying the last and first byte of 2nd and 1st no.

;multiplying the last and first byte of 1st and 2nd no.

;multiplying the first byte of the two no.

12

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.asm C:>link a1.obj C:>masm a2.asm C:>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 byte extrn summation far .data sum db 35h ans db ? .code mov ax,@data mov ds,ax call summation int 3 end a2.asm .model small extrn sum byte, ans byte public summation .code summation proc far 13

mov al,sum add bh,al mov ans,bh summation endp end 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

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 char next: 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 compare again: mov al,[si] cmp al,bl ;comparing with lower case jb next mov dl,20h sub al,dl ;converting lower in to upper 15

mov [si],al next: 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 compare again: 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],al next: 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

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 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 .data a label byte max db 20 actual db ? keys db 20 dup ( ) .code mov ah,0ah lea dx,a int 21h int 3 end (a) mov ah,01h ;Request key board input with echo int 21h Al register will contain the ASCII code of the key being pressed. (b) mov ah,07h ;Request key board input without echo int 21h Entered 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

;Maximum charaters to be read ;Actual characters to be read ;Characters will be stored here

;request keyboard input ;load address of parameter list ;call interrupt service

(a)

mov ah,0h int 16h

;Request key board

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 Mode Mov ah,00h Mov al,03h ;Standard Colour text mode Int 10h Set Cursor Size Mov ah,01h Mov ch,00h ;Start Scan line Mov cl,14h ;End Scan line Int 10h Set Cursor Position Mov ah,02h Mov bh,0h Mov dh,12h Mov dl,30h Int 10h (4) ;Page 0 ;Row 12 ;Column 30

(2)

(3)

Select Active Page Mov ah, 05h Mov al,page Int 10h ;page = 0,1,2 or 3

(5)

Scroll up screen Mov ax,601h ;Request scroll up one line Mov bh,61h ;Brown back ground , blue foreground Mov cx,0000h ;From 00 : 00 Mov dx,184fh ;24 : 79 Full screen int 10h

(6)

Display a character a cursor position Mov ah,0ah 18

Mov al,char Mov bh,page no. Mov cx,repetition Int 10h (7)

;How many times character to be ;displayed

Display character and attribute at cursor mov ah,09h mov al,01h mov bh,0 mov bl,16h mov cx,60 int 10h

;Blue = Back ground, Brown = Foreground

(7)

Display a string terminated with dollar ($) sign Mov ah,09h Lea dx,string Int 21h

19

PRACTICAL 9
Aim: To perform Mouse Operations using software interrupts. Explanation: (1) Initialize mouse Mov ax, 0h Int 33h Display Mouse pointer Mov ax, 01h Int 33h Conceal the mouse pointer Mov ax, 02h Int 33h Get Button status and pointer location Mov ax, 03h Int 33h Above routine will return BX = Status of button Bit 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-ordinates DX = Vertical Co-ordinates Set pointer location Mov ax,04h Mov cx,horizontal Mov dx,vertical Int 33h Task: Show the mouse Click mouse and get button status information Click mouse and get the pointer location

(2)

(3) (4)

(5)

20

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 text Int 10h Set cursor size Mov ah,01h Mov ch,0 Mov cl,14 Int 10h Set color palette ;Start scan line ;end scan line

(2)

(3)

(i) Select background color Mov ah,0bh Mov bh,0 Mov bl,04 Int 10h ;Select Background color ;color red

(ii) select paletter for graphics, where bl contains the palette ( 0 or 1 ) mov ah,0bh mov bh,01h mov bl,0 int 10h (4) Write pixel dot Mov ah,0ch Mov al,03 Mov bh,0 Mov cx,200 Mov dx,500 Int 10h (5) Read pixel dot Mov ah,0dh 21

;number 0 (green,red,brown)

;Page no. ;column ;row

Mov bh,0 Mov cx,80 Mov dx,110 Int 10h

;page no. ;column ;row

22

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,00h Mov al,11100011b Mov dx,0 Int 14h (2) Transmit character Mov ah,01h Mov al,34h Mov dx,0 Int 14h (3) Receive character Mov ah,02h Mov dx,0 Int 14h ;Al contains the character received (4) Return status of communications port Mov ah,03h Mov dx,0 Int 14h Ah, and al contain the line status and modem status respectively. ;Ascii value of character to be ;transmitted ;Line parameters ;Com1 serial port

23

Anda mungkin juga menyukai