1 / 9

CS 206D Computer Organization Lab6

CS 206D Computer Organization Lab6. MUL – multiplication . Unsigned Multiplication Syntax: MUL source Byte Signed Multiplication IMUL source. Byte Form The multiplier (8 bit) is contained in the source field The multiplicand is assumed to be in AL.

saima
Download Presentation

CS 206D Computer Organization Lab6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 206D Computer Organization Lab6 CS 111

  2. MUL – multiplication • Unsigned Multiplication • Syntax: MUL source • Byte Signed Multiplication • IMUL source • Byte Form • The multiplier (8 bit) is contained in the source field • The multiplicand is assumed to be in AL. • The 16-bit product (result) will be in AX. • The source may be a byte register or a memory byte. It cannot be a constant. • Word Form • The multiplier (16 bit) is contained in the source field • The multiplicand is assumed to be in AX. • The 32 bit product (result) will be split over two registers. The most significant 16 bits will be in DX and the least significant bits will be in AX (This is referred to as DX:AX). • The source may be a word register or a memory word. It cannot be a constant CS 111

  3. DIV – Division • Unsigned Division Instruction • Syntax: DIV divisor • Signed Division Instruction • Syntax: IDIV divisor • These instructions divide 8 (or 16) bits into 16 (or 32) bits. The quotient and remainder will be the same size as the divisor. CS 111

  4. DIV – Division • Byte Form • The divisor (8-bit) is contained in the divisor field • The 16-bit dividend is assumed to be in AX. • After the division the 8 bit quotient is in AL and the 8-bit remainder is in AH. • The divisor cannot be a constant! • Word Form • The divisor (16-bit) is contained in the divisor field . • The 32 bit dividend is assumed to be in DX:AX. • After the division, the 16 bit quotient is in AX and the 16-bit remainder is in DX. • The divisor cannot be a constant! CS 111

  5. Question 2: • Write a program read a positive binary number (8-digits maximum) then determine whether the number is prime or not. CS 111

  6. .MODEL SMALL .STACK 100H .DATA MSG1 DB 'ENTER A POSITIVE BINARY NUMBER ( MAX. 8-BIT ) : $' MSG2 DB 0AH,0DH,'IT IS NOT PRIME','$' MSG3 DB 0AH,0DH,'IT IS PRIME','$' ILLEGAL DB 0DH,0AH,'ILLEGAL CHARACTER. TRY AGAIN : $' NUM DB 0 .CODE MAIN PROC MOV AX, @DATA ; initialize DS MOV DS, AX LEA DX, MSG1 ; load and display the string PROMPT_1 MOV AH, 9 INT 21H

  7. ;BINARY INPUT BEGIN: ; jump label MOV CX, 8 ; initialize loop counter ; clear BX MOV AH, 1 ; set input function INPUT: ; loop label INT 21H ; read a digit CMP AL, 0DH ; compare input and CR JE PRIME_OR_NOT CMP AL, 30H ; compare AL with 0 JL ERROR ; jump to label =ERROR if AL<0 CMP AL, 31H ; compare AL with 1 JG ERROR ; jump to label ERROR if AL>1 AND AL, 0FH ; convert ascii to decimal code SHL NUM, 1 ; shift BL by 1 position towards left OR NUM, AL ; place the input decimal digit in BL LOOP INPUT ; jump to label @INPUT if CX!=0 ERROR: ; jump label LEA DX, ILLEGAL ; load and display the string ILLEGAL MOV AH, 9 INT 21H

  8. PRIME_OR_NOT: MOV AH,0 MOV AL, NUM MOV CL,2 DIV CL ; number / 2 MOV CL,AL; keep quotient (largest divisor) in cl LBL1: MOV AH,0 MOV AL,NUM DIV CL CMP AH,0; check if CL is a divisor JE NOT_PRIME DEC CL CMP CL,1 JNE LBL1 ; has no positive divisors except 1 and itself. JMP PRIME

  9. NOT_PRIME: ; display not prime msg MOV AH,9 LEA DX,MSG2 INT 21H JMP EXIT PRIME: ; display prime msg MOV AH,9 LEA DX,MSG3 INT 21H MAIN ENDP END MAIN

More Related