MCS-012 Computer Organisation and Assembly Language Programming Free Solved Assignment

IGNOU MCS-012-Computer Organisation and Assembly Language Programming, Latest Solved Assignment (July 2023 - January 2024 )

ignoustudymentor.com

Q4. (a) Write a program using 8086 assembly Language (with proper comments) that accepts three different digits as input from the keyboard. Each digit is first converted to a binary equivalent. The binary values of these three digits are compared and the middle value is put in the AL register. This AL register is multiplied with each value of a byte array of size 6, which is stored in the memory. The result of the multiplicationis stored in the same memory location. You may assume the byte array has the values 02h, 06h, 08h, 03h, 01h, 05h. Make suitable assumptions, if any.

Ans. ORG 100h
MOV AH, 0 ; Clear AH register
MOV CX, 3 ; Set loop counter to 3 (for 3 digits)
; Loop to input three digits
INPUT_LOOP:
; Input a decimal digit
MOV AH, 1 ; Function to read character from keyboard
INT 21h ; Read character
SUB AL, ‘0’ ; Convert ASCII digit to binary

; Store the digit in an array
MOV [DI], AL ; Store digit in memory at address DI
INC DI ; Move to next memory location

LOOP INPUT_LOOP ; Repeat for three digits

; Convert the binary digits to binary-coded decimal (BCD)
MOV DI, OFFSET DigitsArray ; DI points to the start of the array
MOV CX, 3 ; Set loop counter to 3 (for 3 digits)

BCD_CONVERSION_LOOP:
; Convert binary digit to BCD
MOV AL, [DI] ; Load binary digit from memory
AAA ; Adjust AL for BCD conversion

; Store BCD digit in memory
MOV [DI], AL ; Store BCD digit back in memory
INC DI ; Move to next memory location

LOOP BCD_CONVERSION_LOOP ; Repeat for three digits

; Find the middle value among the BCD digits
MOV DI, OFFSET DigitsArray ; Reset DI to point to the start of the array
MOV AL, [DI] ; Load the first BCD digit to AL
MOV AH, [DI+1] ; Load the second BCD digit to AH

CMP AL, AH ; Compare the first and second digits
JC SKIP ; Jump if CF is set (AL < AH)
XCHG AL, AH ; Swap AL and AH if AH is smaller

CMP AL, [DI+2] ; Compare the first (or swapped second) digit with the thirddigit
JNC SKIP ; Jump if CF is clear (AL >= [DI+2])
MOV AL, [DI+2] ; Load the third digit to AL
; Multiply the middle value with each element in the byte array
SKIP:
MOV DI, OFFSET ByteArray ; DI points to the start of the byte array
MOV CX, 6 ; Set loop counter to 6 (for 6 elements)

MULTIPLICATION_LOOP:
MOV AH, 0 ; Clear AH before multiplication
MUL [DI] ; Multiply AL with the byte from memory
; Store the result of multiplication in memory
MOV [DI], AL ; Store result back in memory
INC DI ; Move to next memory location

LOOP MULTIPLICATION_LOOP ; Repeat for all array elements

; Terminate the program
MOV AH, 4Ch ; DOS function to exit
INT 21h ; Call DOS interrupt

; Data section
DigitsArray DB 3 DUP(?) ; Array to store the input digits (BCD)
ByteArray DB 02h, 06h, 08h, 03h, 01h, 05h ; Byte array of size 6

END

(b) Write a NEAR subroutine using 8086 assembly Language (with proper comments) that returns the average value of the values stored in a byte arrayof length 3. All three values of the byte array are passed to the subroutine inthestack. You should write both the calling program and subroutine.

Ans. Subroutine:
ORG 100h

; Subroutine to calculate the average value of a byte array of length 3
AVERAGE_SUBROUTINE:
PUSH BP ; Save the value of BP on the stack
MOV BP, SP ; Set BP to point to the top of the stack

; Load the byte array values from the stack
MOV AL, [BP+4] ; Load the first value from the stack
ADD AL, [BP+6] ; Add the second value to AL
ADD AL, [BP+8] ; Add the third value to AL

; Calculate the average by dividing the sum by 3
MOV AH, 0 ; Clear AH
MOV BL, 3 ; Load divisor (3)
DIV BL ; Divide AL by BL, result in AL (average)
POP BP ; Restore BP from the stack
RET ; Return to the calling program

; Data section (not needed for the subroutine)

END

Calling Program:
ORG 200h

MOV AL, 10 ; First value of the byte array (example)
MOV AH, 20 ; Second value of the byte array (example)
MOV BL, 30 ; Third value of the byte array (example)

PUSH AL ; Push the values onto the stack
PUSH AH
PUSH BL

CALL AVERAGE_SUBROUTINE ; Call the subroutine

ADD SP, 6 ; Clean up the stack (remove the pushed values)
MOV DL, AL ; Result of the average calculation

; Display the result using DOS interrupt
MOV AH, 02h ; Function to display character
ADD DL, ‘0’ ; Convert to ASCII
INT 21h

MOV AH, 4Ch ; DOS function to exit
INT 21h

END

(c) Explain the following in the context of 8086 Microprocessor with the helpof an example or a diagram:

(i) Use of code segment and stack segment registers for computing the respective 20-bit addresses.

(ii) Any 4 flags of the flag register of 8086 micro-processor

(iii) Any four shift instructions of 8086 micro-processor

Ans. (i) Use of code segment and stack segment registers for computing the respective 20-bit addresses.

In the 8086 Microprocessor, the code segment register (CS) and stack segment register (SS) are used to compute the respective 20-bit addresses. The CS register stores the base address of the code segment, which contains the executable
program instructions. By adding the offset address, stored in the instruction pointer register (IP), to the CS register, the 20-bit physical address of the next instruction is computed. Similarly, the SS register stores the base address of the stack segment, which is used for storing temporary data during program execution. By adding the offset address, stored in the stack pointer register (SP), to the SS register, the 20-bit physical address of the stack is computed.

(ii) Four flags of the flag register in the 8086 microprocessor are:

  1. Carry Flag (CF): It is set when there is a carry or borrow during arithmetic operations.
  2. Zero Flag (ZF): It is set when the result of an arithmetic or logical operation is zero.
  3. Sign Flag (SF): It is set when the result of an arithmetic operation is negative.
  4. Overflow Flag (OF): It is set when the result of a signed arithmetic operation overflows.

(iii) Four shift instructions of the 8086 microprocessor are:

  1. SHL (Shift Left): This instruction shifts the bits of a register or memory operand to the left, filling the empty bit positions with zeros.
  2. SHR (Shift Right): This instruction shifts the bits of a register or memory operand to the right, filling the empty bit positions with zeros.
  3. SAL (Shift Arithmetic Left): This instruction shifts the bits of a register or memory operand to the left, filling the empty bit positions with the value of the sign bit.
  4. SAR (Shift Arithmetic Right): This instruction shifts the bits of a register or
    memory operand to the right, filling the empty bit positions with the value of thesign bit.
ignoustudymentor.com

MCS-012

Handwriting Assignment

MCS-012

Other Questions With Answers

Other Subjects

Click Here

Assignment Submission Last Date

The IGNOU open learning format requires students to submit study Assignments. Here is the final end date of the submission of this particular assignment according to the university calendar.

30th April (if Enrolled in the June Exams)

31st October (if Enrolled in the December Exams)

Student Quick Services

error: Content is protected !!