1 / 12

CS 206D Computer Organization Lab8

CS 206D Computer Organization Lab8. Exercise 1. - Write an assembly program that ask the user to enter a positive hex (2 digits) number and multiply the input by 2. Then print the result in Binary form. .MODEL SMALL .STACK 100H .DATA

Download Presentation

CS 206D Computer Organization Lab8

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 Lab8 CS 111

  2. Exercise 1 - Write an assembly program that ask the user to enter a positive hex (2 digits) number and multiply the input by 2. Then print the result in Binary form. CS 111

  3. .MODEL SMALL .STACK 100H .DATA MSG1 DB 'ENTER A POSITIVE HEX NUMBER (2 digit) : $' MSG2 DB 0AH,0DH,'THE RESULT IN BINARY: ','$‘ .CODE MAIN PROC MOV AX, @DATA ; initialize DS MOV DS, AX LEA DX, MSG1 ; load and display the string MOV AH, 9 INT 21H

  4. XOR BX,BX ; BX WILL HOLD THE INPUT MOV AH,1 INT 21H WHILE: CMP AL, 0DH ; CR? JE ENDWHILE CMP AL,'9' ; AL>9? JG LETTER ; Al is letter ;ELSe AL is digit AND AL , 0FH JMP SHIFT LETTER: SUB AL , 37H SHIFT: SHL BX,4 OR BL,AL ;Insert value to bx INT 21H ; Read again JMP WHILE

  5. ENDWHILE: LEA DX, MSG2 MOV AH, 9 INT 21H MOV AL,BL MOV CL , 2 ; Multiply by 2 MUL CL ; The result will be stored in AX MOV BX,AX ;Print ax in binary form MOV CX,16 ; AX is 16 bits MOV AH,2 PRINT: ROL BX,1 JC ONE ;IF (CF == 1) ;Else cf = 0 MOV DL, 30H ; To print 0 JMP DISPLAY ONE: MOV DL, 31H ;To print 1 DISPLAY: INT 21H LOOP PRINT \

  6. Addressing mode CS 111

  7. Register Indirect Mode • The offset address of the operand is contained in a register. I.e. The register acts as a pointer to the memory location. • The register must be one of the following: BX, SI, DI. BP. • Format: [register] Ex. suppose that SI contains 0110h, and the word at 0110h contains 1884h. • MOV AX, [SI] • MOV AX, SI CS 111

  8. Based and Indexed Addressing Modes • The operand’s offset address is obtained by adding a number called a displacement to the contents of a register. • Syntax: [register + displacement] [displacement + register] [register] + displacement displacement + [register] displacement[register] CS 111

  9. Based and Indexed Addressing Modes • What will be the result of following instructions: Ex. Suppose that ALPHA is declared as: ALPHA DW 0123H, 0116H, 0789H, 0ABCDH In segment address by DS. Suppose also that: • BX contains 2 offset 0002 contains 1022 h • SI contains 4 offset 0004contains 2DDCh • DI contains 1 CS 111

  10. Based and Indexed Addressing Modes CS 111

  11. Homework 6 Question 1: Write a program that Sum the values of even index of array A. Suppose that Array A contains: CS 111

  12. .DATA • MSG DB 'THE SUM OF ARRAY ELEMENTS: $' • A DB 2,3,5,8,1,4 • .CODE • MOV AX, @DATA ; initialize DS • MOV DS, AX • XOR SI,SI ;clear SI • XOR AX,AX ;AX holds sum • MOV CX,3; no. of indexes in A • TOP: • ADD AL,A[SI] ;Sum= Sum + element • ADD SI,2; to go the next index • LOOP TOP ;loop until done • MOV AH,9; display the string MSG • LEA DX, MSG • INT 21h • MOV DL,AL • MOV AH,2 • INT 21H Homework 6 CS 111

More Related