Вы находитесь на странице: 1из 15

EXPERIMENT NOAIM : Write a program to find the average of to temperature named HI_TEMP and LO_TEMP and put the

result in memory location AV_TEMP. PROGRAME : DATA SEGMENT HI_TEMP DB 50H LO_TEMP DB 20H AV_TEMP DB ? DATA ENDS ; Maximum temperature storage ; Minimum temperature storage ; Store average temperature here

CODE SEGMENT ASSUME CS: CODE, DS:DATA

START: MOV AX, DATA MOV DS,AX MOV AL,HI_TEMP ADD AL,LO_TEMP

; Initialize data segment

; get the high temp. value ;add low temp. value to it

MOV AH,00H ADC AH, 00H MOV BL, 02H DIV BL

;clear AH register ; put carry of LSB addition in AH ; Load divisor in BL register ; Divide AX by BL. Quotient in AL And remainder in AH

MOV AV_TEMP, AL MOV AH,4CH INT 21H CODE ENDS END START

; store the result ;Terminate program and ; Return to DOS

EXPERIMENT AIM : Find out the largest no. from an unordered array of sixteen 8-bit numbers stored sequentially in the memory locations starting at offset 0500H in the segment 2000H. PROGRAME : Assume that sixteen 8-bit no. are stored sequentially in the memory location starting at offset 0500H in the segment.

2000H : 0500H 2000H : 0502H 2000H : 0504H 2000H : 0506H 2000H : 5008H 2000H : 050AH 2000H : 050CH 2000H : 050EH

15H 25H 02H 50H 12H 2BH 32H 46H

2000H : 0501H 2000H : 0503H 2000H : 0505H 2000H : 0507H 2000H : 0509H 2000H : 050BH 2000H :050DH 2000H : 050FH

10H 8EH 09H 18H 48H 56H 73H 24H

MOV AX, 2000H MOV DS, AX

; Initialize data ; segment DS with value 2000H

MOV SI, 0500H MOV CI, 16 MOV AL, [SI] AGAIN: CMP AL,[SI+1] JGE NEXT

; initialize SI with starting Address of array ; initialize counter =16 ; get the first no. in AL ;compare with the next no. ; go to NEXT if no. in AL ; is greater than or equal to next no.

MOV AL, [SI+1]

; otherwise store next no. ; as a greater no.

NEXT : INC SI DEC CL JNZ AGAIN HLT

;increment array pointer ; decrement counter ; check if all no. are compared ; stop

EXPERIMENT NO AIM : move a byte string, 16 byte long, from the offset 0200H to 0300Hin the segment 7000H. PROGRAM : assume that a byte string of 16 byte is stored at offset 0200H. WITHOUT USING STRING INSTRUCTION MOV AX, 7000H MOV DS, AX MOV SI, 0200H MOV DI, 0300H MOV CL, 16 BACK: MOV AL, [SI] MOV [DI], AL INC SI INC DI DEC CL JNZ BACK HLT ; [initialize date segment DS ; with value 7000H] ; Load offset of start of source string into SI ; Load offset of start of destination into DI ; Load length of string in CX as counter ; Get the byte from source location ; Store it in the destination location ; increment source byte pointer ; increment destination byte pointer ; Decrement counter ; If all byte are not transferred, repeat ; Stop

USING STRING INSTRUCTION MOV AX, 7000H MOV DS, AX MOV SI, 0200H MOV DI, 0300H CLD ; [Initialize data segment DS ; with value 7000H] ; Load offset of start of source string into SI ; Load offset of start of destination into DI ; Clear direction flag to auto ; increment SI and DI MOV CX, 16 REP MOVSB ; Load length of string in CX as counter ; Decrement CX and move string ; byte until CX = 0 HLT ; Stop

EXPERIMENT NOAIM : Write a program to add a profit factor to each element in a COST array and put the result in a PRICES array, where profit factor is 15H and COST = 20H, 28H, 15H, 26H, 19H, 27H, 16H,29H. PROGRAME : PROFIT DATA EQU 15H SEGMENT COST DB 20H ,28H, 15H, 26H, 19H, 27H, 16H, 29H, PRICES DB 8 DUP (0) DATA CODE ENDS SEGMENT ASSUME CS : CODE, DS : DATA START : MOV AX, DATA MOV DS, AX MOV CX, 0008H MOV BX, 0000H BACK : MOV AL, COST [BX] ADD AL, PROFIT ; [Initialize ; data segment] ; Initialize counter ; Initialize pointer ; Get cost from COST array ; Add the profit in cost ; ;Profit = 15 Rs.

DAA MOV PRICES [BX], AL INC BX DEC CX JNZ BACK MOV AH, 4CH INT 21H CODE ENDS ENDS START

; Decimal adjust result ; Store result in PRICES at [BX] ; Point to next cost in array COST ; decrement the counter ; if not last cost, do again ; Terminate the program and ; return to DOS

EXPERIMENT NOAIM : Write a program to find out the number of positive numbers and negative numbers from a given series of signed numbers. PROGRAM : Sign of the number is indicated by the MSB Bit of the number. If MSB is 1, the number is negative ;otherwise it is positive .we can check the status of most significant bit by moving it into the carry flag and then checking the status of carry flag .this can be implemented by any of the following instruction: RCL,ROL, SAL or SHL COUNT DATA EQU 05H SEGMENT NUMER POS_N MEG_N DATA CODE ASSUME START : ENDS SEGMENT CS: CODE, DS: DATA MOV AX, DATA MOV DS, AX ; ; [initialize data segment] DW 1234H, 5678H, 2346H,0526H,5926H DB DH 0H 0H

MOV CL, COUNT

Initialize counter Initialize pointer Get the number Get the MSB of number in carry flag Check whether the number Is positive or negative

MOV SI, OFFSET NUMBER ; AGAIN: MOV AX,[SI] RCL, AX, 01 JC NEG ; ; ;

INC POS_N JMP NEXT NEG: NEXT: INC NEG_N ADD SI, 02 DEC CL JNZ AGAIN MOV AH, 4CH INT 21H CODE ENDS END START ; ; ; ; ; ;

; ;

Increment the positive number count Go to NEXT

Increment the negative number count Increment SI by 2 to point the next number Decrement counter and check If all numbers are over, if not repeat Terminate program and return to DOS

EXPERIMENT NOAIM : Write a program that performs the addition, subtraction, multiplication, division of the given operands. Perform BCD operation for addition and subtraction. PROGRAM : DATA SEGMENT NO1 NO2 SUM SUBT BORROW PROD Q R DATA CODE ENDS SEGMENT ASSUME CS : CODE, DS : DATA START : MOV AX, DATA ; [Initialize DB DB DW DB DB DW DB DB 80H 40H 0H OH 0H 0H 0H 0H

MOV DS, AX MOV AL, NO1 ADD AL, NO2 DAA

; data segment] ; Get the first number ; add second number to it ; decimal adjust result

MOV BYTE PTR SUM, AL ; store lower byte of result JNC NEXT INC [SUM + 1] ; make higher byte = 1

NEXT :

MOV AL, NO1 SUB AL, NO2 DAS MOV SUBT, AL JNC NEXT 1 MOV BORROW, 1

; Get the first number ; subtract second number from it ; Decimal adjust after subtraction ; store lower byte of result

; Borrow is 1 ; Get the first number ; multiply by second number ; save the product ; Get the first number

NEXT 1:

MOV AL, NO1 MUL BL MOV PROD, AX MOV AL, NO1

MOV AH, 00H DIV BL MOV Q, AL MOV R, AH MOV AH, 4CH INT 21H CODE ENDS END START

; make AH = 0 ; Divide AX by BL ; Save the quotient ; Save the remainder ; Terminate the program and ; return to DOS

EXPERIMENT NOAIM : A program to find out the number of even and odd number from a given series of 16-bit hexadecimal numbers. PROGRAM : By checking the LSB of the number we can decide whether the number is even or odd. When LSB is 0, the number is even, otherwise, it is odd. We can check the status of LSB bit by moving it into the carry flag and then checking the status of carry flag. This can be implemented by any of the following instructions : SHR, SAR, RCR, ROR. COUNT DATA EQU 5H SEGMENT NUMBER DW 1234H, 5678H, 5129H, 7235H EVEN_N DB 0H ODD_N DB OH DATA CODE ENDS SEGMENT

ASSUME CS : CODE, DS : DATA START : MOV AX, DATA ;[Initialize

MOV DS, AX MOV CL, COUNT

; data segment] ; Initialize counter

MOV SI, OFFSET NUMBE; Initialize pointer AGAIN : MOV AX, [SI] SHR AX, O1 JC ODD INC EVEN_N JMP NEXT ODD NEXT : INC ODD_N : ADD SI, 02 ; Get the number ; Get the LSB of number in carry flag ; check whether the number is even or odd ; Increment the even number count ; Go to NEXT ; Increment the odd number count ; Increment SI by 2 to point the next ; number DEC CL JNZ AGAIN MOV AH, 4CH INT 21H CODE ENDS END START ; Decrement counter and ; If all number are over, if not do again ; Terminate program and ; return to DOS

Вам также может понравиться