86% found this document useful (7 votes)
411 views

Assignment 1

The document contains 10 programming problems involving string manipulation, matrix addition, character searching, ASCII arithmetic, and other operations. The problems demonstrate use of various x86 assembly language instructions like AAA, AAM, REPNE SCASB, and others. Sample data and code segments are provided for each problem to solve.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
86% found this document useful (7 votes)
411 views

Assignment 1

The document contains 10 programming problems involving string manipulation, matrix addition, character searching, ASCII arithmetic, and other operations. The problems demonstrate use of various x86 assembly language instructions like AAA, AAM, REPNE SCASB, and others. Sample data and code segments are provided for each problem to solve.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1) Analyze the following program and come with the result in terms of registers and flags affected after

the execution of the div instructions. Assume that the Dividend is 1525H and the Divisor 0FFH available in continuous locations starting at 7000:0000h. code segment assume cs:code start: mov ax,7000h mov ds,ax mov bx,0000h mov ax,[bx] ------------------------------------AX value becomes 1525h,i.e, AH = 15h and AL = 25H mov dl,[bx+2] ---------------------------------BL become FFh div dl --------------------------------------------AL contains the quotient 15h and AH contains the remainder 3Ah mov [bx+3],ax --------------------------------the memory location at 7000:0003 contains the value 15h int 3h code ends end start Note that: no flags are affected except the IF (interrupt flag) IF = 1.

2) Write a program to mask bits D3D2D1D0 and to set bits D5D4 and to invert bits D7D6 of the AX register. org 100h --------------------------------assume we are starting from an offset of 100h mov al,0ffh -----------------------------assum initial value of AX = 00ffh R:and al,0f0h---------------------------the lower four bits of AX are reset or al,30h--------------------------------D5D4 of AX are set xor al,0c0h-----------------------------D7D6 are inverted if D7D6 = 11 D7D6 = 00 else D7D6 =11 jmp R: ---------------------------------repeat the operation infinitely. ret

3) Write a program to add two ASCII numbers and store the result as ASCII numbers. (Use AAA instruction). Data segment Num1 db 1234h Num2 db 5678h Sum db ? Data ends code segment assume cs:code, ds:Data start: mov ax, Data mov ds,ax mov bx,num1 mov ax,num2 add ax,bx AAA mov sum,ax int 3h code ends end start

4) Write a program to multiply two ASCII numbers and store the result in the ASCII form. (use AAM instruction). Data segment Num1 db 12h Num2 db 34h mul db ? Data ends code segment assume cs:code, ds :Data start: mov ax, Data mov ds,ax mov bx,num1 mov ax,num2 mul ax AAM mov mul,ax int 3h code ends end start

5) Write a program to check whether the lower and upper nibbles of a byte are different. The data is available in the first byte of the ES. If they are the same store FF in the next location else store 00H

code segment assume cs :code start : mov ax, 7000 mov es,ax mov DI ,0000h mov al, [di] mov bl,al mov cl, 04h AND bl,0fh AND al,0f0h ROR al,cl cmp al,bl je down mov [di+1],00h call end1 down: mov [di+1],0ffh end1: code ends end start

6) Write a program to find the number of occurrences of the largest item in an array on N bytes of DS. DATA SEGMENT A DB 5,2,5,6,4,3 B DB ? DATA ENDS CODE SEGMENT ASSUME DS:DATA,CS:CODE START: MOV AX,DATA MOV DS,AX MOV CX,0000 MOV CL,06 LEA BX,A MOV AL,00 MOV AH,BYTE PTR[BX] L1:CMP AL,BYTE PTR[BX] JNC L2 MOV AL,BYTE PTR[BX] L2:CMP AH,BYTE PTR[BX] JC L3 MOV AH,BYTE PTR[BX] L3:INC BX DEC CL CMP CL,00 JNZ L1 mov bl,ah MOV AH,4CH INT 21H CODE ENDS END START

7) Write a program to add two NxN Matrices available in the DS in contiguous memory locations. ( Assume N = 10) data segment arr1 db 10h,20h,30h,40h,50h,60h,70h,80h,90h,0Ah arr2 db 10h,20h,30h,40h,50h,60h,70h,80h,90h,0Ah arr3 db 10 dup (0) data ends code segment assume cs:code , ds:data start: mov ax,data mov ds,ax lea si,arr1 lea di,arr2 lea bx,arr3 mov cl,10 l1: mov al,[si] add al,[di] mov [bx],al inc si inc di inc bx dec cl jnz l1 mov ah,4ch int 21h code ends end start

8) Write a program to reverse a string available in DS to ES

Data Segment str1 db 'haftu hagos','$' strlen1 dw $-str1 strrev db 20 dup(' ') Data Ends

Code Segment Assume cs:code, ds:data start: mov ax, data mov ds, ax mov es, ax mov cx, strlen1 add 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 loop L1 mov al, [si] mov [di], al inc di mov dl, '$' mov [di], dl Print: mov ah, 09h lea dx, strrev int 21h Exit: mov ax, 4c00h int 21h Code Ends End start

9) Write a program to find out a given byte/character is present in a string or not. (Use REPNE SCASB instruction). DATA SEGMENT MSG1 DB 10,13,'CHARACTER FOUND :) $' MSG2 DB 10,13,'CHARACTER NOT FOUND :($' MSG3 DB 10,13,'ENTER THE STRING : $' MSG4 DB 10,13,'ENTER THE CHARACTER TO BE SEARCHED : $' NEW DB 10,13,'$' INST DB 10 DUP(0) DATA ENDS

CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX LEA DX,MSG3 MOV AH,09H INT 21H MOV BX,00 UP: MOV AH,01H INT 21H CMP AL,0DH JE DOWN MOV [INST+BX],AL INC BX JMP UP DOWN: LEA DX,NEW MOV AH,09H INT 21H LEA DX,MSG4 MOV AH,09H INT 21H MOV AH,01H INT 21H MOV CX,BX MOV DI,0 UP1: CMP AL,[INST+DI] JE DOWN1 INC DI LOOP UP1 LEA DX,MSG2 MOV AH,09H INT 21H

JMP FINISH DOWN1: LEA DX,MSG1 MOV AH,09H INT 21H FINISH: mov ah,4ch INT 21h CODE ENDS END START

10) Write a program to convert a lower case string available in DS to an Upper case string using the string instructions.

DIS MACRO STR MOV AH,09H LEA DX,STR INT 21H ENDM DATA SEGMENT MSG1 DB "ENTER YOUR STRING : $" MSG2 DB "CONVERTED STRING IS : $" STR1 DB 20 DUP('$') LINE DB 10,13,'$' DATA ENDS

CODE SEGMENT ASSUME DS:DATA,CS:CODE

START: MOV AX,DATA MOV DS,AX DIS MSG1 MOV AH,0AH LEA DX,STR1 INT 21H DIS LINE MOV CH,00 MOV CL,BYTE PTR[STR1+1] LEA SI,STR1+2 L1: MOV AH,BYTE PTR[SI] CMP AH,'A' JL L4 CMP AH,'Z' JG L2 ADD BYTE PTR[SI],32 JMP L3 L2:CMP AH,'a' JL L4 CMP AH,'z' JG L4 SUB BYTE PTR[SI],32 L3:INC SI

LOOP L1 DIS MSG2 DIS STR1+2 L4:MOV AH,4CH INT 21H CODE ENDS END START

You might also like