Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

5.prog To Perform Bit Manipulation To Check If Bit Is Odd or Even and Positive or Negative

The document contains 14 programming problems including programs to perform bitwise operations, string manipulation, number sorting/conversion, and mathematical operations like factorial, Fibonacci, and LCM/GCD. The problems cover a range of fundamental programming concepts. Sample code is provided for many of the problems to demonstrate solutions.

Uploaded by

Glen Flav Pais
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

5.prog To Perform Bit Manipulation To Check If Bit Is Odd or Even and Positive or Negative

The document contains 14 programming problems including programs to perform bitwise operations, string manipulation, number sorting/conversion, and mathematical operations like factorial, Fibonacci, and LCM/GCD. The problems cover a range of fundamental programming concepts. Sample code is provided for many of the problems to demonstrate solutions.

Uploaded by

Glen Flav Pais
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

1.Program to perform 16 bit addition and subtraction 2. Program to perform 32 bit addition and subtraction 3.

prog to find square and cube of a number 4.Program to find the factorial of a number 5.Prog to perform bit manipulation to check if bit is odd or even and positive or negative 6.Prog to check bitwise paliandrome 7.Prog to sort an array in ascending and descending order 8.prog to reverse a string 9.program to check if the string is a palindrome 10.prog to check the occurence of a character in a string 11.Prog to generate first 10 fibonacci numbers 13.prog to find LCM and GCD of two given numbers 14.Prog to convert BCD to binary equivalent

Programs: 1.Program to perform 16 bit addition and subtraction


;16 BIT ADDAND SUB data segment num1 dw 2222h num2 dw 1212h sum dw ? res dw ? data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ax,num1 mov bx,num2 adc ax,bx mov sum,ax jmp l2 l2:mov ax,num1 sbb ax,bx mov res,ax mov ax,4c00h int 3h

code ends end start

2. Program to perform 32 bit addition and subtraction


;32 BIT ADD AND SUB data segment num1 dw 8888h,8888h num2 dw 2222h,2222h sum dw 2 dup(0) diff dw 2 dup(0) data ends code segment assume cs:code,ds:data start:mov ax,data mov ds,ax mov ax,num1 add ax,num2 mov sum,ax mov ax,num1+2 adc ax,num2+2 down:mov sum+2,ax jmp sub1 sub1 :mov ax,num1 sub ax,num2 mov diff,ax mov ax,num1+2 sbb ax,num2+2 mov diff+2,ax

mov ah,4ch int 3h code ends end start

4) PROGRAM TO FIND THE FACTORIAL OF A NUMBER. DATA SEGMENT NUM DB 05H

FACT DW ? DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV AX,DATA MOV DS,AX SUB DX,DX SUB CX,CX MOV AX,01H MOV CL,NUM CMP CL,00H JE STOP BACK: MUL CL LOOP BACK MOV FACT,AX MOV FACT+2,DX STOP: INT 3H CODE ENDS END START

5.Prog to perform bit manipulation to check if bit is odd or even .


:no is even or odd data segment x dw 25h msg1 db 19,13,'No is even$' msg2 db 10,13,'No is odd$' data ends code segment

assume cs:code,ds:data start:mov ax,data mov ds,ax mov ax,x test ax,01h jnz exit lea dx,msg1 mov ah,09h int 21h jmp last exit:lea dx,msg2 mov ah,09h int 21h last:mov ah,4ch int 21h code ends end start

6.Prog to check bitwise paliandrome DATA SEGMENT A DB 88H RES DB ? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV BL,A MOV AL,A MOV CX,04H ABOVE:MOV DX,0 ROL AL,01H JNC NEXT INC DL NEXT: ROR BL,01H JNC LI

INC DH LI:CMP DH,DL JNZ OVER LOOP ABOVE MOV RES,0FFH JMP FINISH OVER:MOV RES,0AAH FINISH: MOV AH,4CH INT 21H CODE ENDS END START 7.Prog to sort an array in ascending and descending order

8.Prog to reverse a string DATA SEGMENT STR1 DB 'HELLO' STR2 DB 8 DUP(?) DATA ENDS code segment ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV SI,7 MOV CX,8 MOV DI,0

BACK: MOV AL,STR1[SI] MOV STR2[DI],AL DEC SI INC DI LOOP BACK MOV AH,4CH INT 21H CODE ENDS END START 9.program to check if the string is a palindrome
Data Segment str1 db 'MADAM','$' strlen1 dw $-str1 strrev db 20 dup(' ') str_palin db 'String is Palindrome.','$' str_not_palin db 'String is not Palindrome.','$' Data Ends Code Segment Assume cs:code, ds:data Begin: 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 mov cx, strlen1 Palin_Check: lea si, str1 lea di, strrev repe cmpsb jne Not_Palin Palin: mov ah, 09h

Not_Palin:

Exit: Code Ends End Begin

lea dx, str_palin int 21h jmp Exit mov ah, 09h lea dx, str_not_palin int 21h mov ax, 4c00h int 21h

10.prog to check the occurence of a character in a string

11.Prog to generate first 10 fibonacci numbers


DATA SEGMENT FIB DW 12 DUP(?) DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX LEA SI,FIB MOV AX,00H MOV BX,01H MOV CX,LENGTH FIB MOV SI,00H DEC CX RPT: ADD SI,02H ADD AL,BL DAA ADD AH,BH XCHG AL,AH

DAA XCHG AL,AH MOV [SI],AX MOV AX,BX MOV BX,[SI] LOOP RPT INT 3H CODE ENDS END START

12.Prog. to find the number of positive,negative numbers and 0s in an array


DATA SEGMENT ARRAY DB 01,-03,00,04,00,00,05 PCOUNT DB ? NCOUNT DB ? ZCOUNT DB ? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX LEA SI,ARRAY SUB CX,CX MOV CL,07H SUB BX,BX SUB DX,DX BACK: MOV AL,[SI] CMP AL,00 JE ZCON JG PCON INC BL JMP NEXT PCON: INC BH JMP NEXT ZCON: INC DL NEXT: INC SI LOOP BACK MOV NCOUNT,BL MOV PCOUNT,BH MOV ZCOUNT,DL INT 3H CODE ENDS END START

13.TO FIND THE GCD AND LCM OF TWO GIVEN BYTES.


DATA SEGMENT NUM1 DW 4 NUM2 DW 6 GCD DW ? LCM DW ? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START : MOV AX,DATA MOV DS,AX MOV AX,NUM1 MOV BX,NUM2 XOR DX,DX NEXT : CMP AX,BX JE STOP JC SUBBA SUB AX,BX JMP NEXT SUBBA : SUB BX,AX JMP NEXT STOP : MOV GCD,AX MOV AX,NUM1 MOV BX,NUM2 MUL BX DIV GCD MOV LCM,AX INT 3H CODE ENDS END START

14.Prog to convert BCD to binary equivalent

DATA SEGMENT NUM DB 12H HEXNUM DB ? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START:MOV AX,DATA MOV DS,AX LEA SI,NUM MOV AL,[SI] MOV BL,[SI] AND BL,0FH AND AL,0F0H MOV CL,04H SHR AL,CL MOV DL,0AH MUL DL ADD AL,BL INC SI MOV [SI],AL INT 3H CODE ENDS END START

You might also like