Princess Nora Bint Abdulrahman University Faculty of Computer and Information Science CS 321 :Computer Organization and assembly language First Semester 1432/1433H Lab Model Answers CS321Lab ModelAnswers ١ L. Aseel AlDabjan Princess Nora Bint Abdulrahman University Faculty of Computer and Information Science CS 321 :Computer Organization and assembly language First Semester 1432/1433H Lab Model Answers First Lab : Q : Write a program which display ? for the user to enter a letter from the keyboard and display the letter on next line. Note: Comments are necessary in your code. Sample Execution: Input ?s SOLUTION : .MODEL SMALL .STACK 100H .DATA .CODE MAIN PROC ; initialize DS MOV AX, @DATA MOV DS, AX ; To display ? on screen for user input MOV AH,2 ; display character function MOV DL,'?' ; character is ? INT 21h ; display it ;Ready to Input from keyboard MOV AH, 1 INT 21H MOV BL,AL ; Save it to other safe data register ;To go to next line MOV AH,2 MOV DL,0DH ; for carriage return INT 21h MOV DL,0AH ; for line feed ( going to beginning of next line) INT 21h ;Display the input Character MOV AH,2 ; display character function MOV DL, BL ; character is in BL INT 21h ; display it ;return to DOS MOV AH, 4CH INT 21h ; Dos exit MAIN ENDP END MAIN ٢ L. Aseel AlDabjan Princess Nora Bint Abdulrahman University Faculty of Computer and Information Science CS 321 :Computer Organization and assembly language First Semester 1432/1433H Lab Model Answers Second Lab Q: Write a program which display "Welcome to CS321 " Note: Comments are necessary in your code. Sample Execution: Welcome to CS321 SOLUTION : .MODEL SMALL .STACK 100H .DATA MSG DB ' Welcome to CS321 $' .CODE MAIN PROC ; initialize DS MOV AX,@DATA ; get data segment MOV DS,AX ; initialize DS ; display message LEA DX,MSG ; get message MOV AH,9 ; display string function INT 21H ; display message ; return to DOS MOV AH, 4CH INT 21H ; DOS exit function ; exit to DOS MAIN ENDP END MAIN ٣ L. Aseel AlDabjan Princess Nora Bint Abdulrahman University Faculty of Computer and Information Science CS 321 :Computer Organization and assembly language First Semester 1432/1433H Lab Model Answers Third hird Lab (practice on arithmetic operation): Q: Write a program which ask user to input two Decimal Numbers whose sum is less than 10 and display their sum in next line . Sample execution: Enter two Decimal Numbers whose sum is less than 10 : 27 The sum is : 9 SOLUTION : Input .MODEL SMALL .STACK 100H .DATA MSG DB ' ENTER two Decimal Numbers whose sum is less than 10: $' MSG1 DB 0AH,0DH,'THE SUM is : $' C2 DB ? .CODE Main PROC MOV AX,@DATA ; initialize DS MOV DS,AX LEA DX,MSG ;display the first message MOV AH,9 INT 21H MOV AH,1 INT 21H ; read and store 1st digit MOV BL,AL INT 21H ; read and store 2nd digit MOV C2,AL ٤ L. Aseel AlDabjan Princess Nora Bint Abdulrahman University Faculty of Computer and Information Science CS 321 :Computer Organization and assembly language ADD BL,C2 ; add the two numbers SUB BL,30H ; * LEA DX,MSG1 ; display second message First Semester 1432/1433H Lab Model Answers MOV AH,9 INT 21H MOV AH,2 ; display result MOV DL,BL INT 21H ;return to DOS MOV AH,4CH INT 21H Main ENDP END Main * when we add the two numbers , suppose we enter 2 and 7 Their ASCII code are 32h and 37h respectively, after adding BL will contais 69h , now we have to SUB 30h to get the ASCII code of 9 and it is 39h. ٥ L. Aseel AlDabjan Princess Nora Bint Abdulrahman University Faculty of Computer and Information Science CS 321 :Computer Organization and assembly language First Semester 1432/1433H Lab Model Answers Forth Lab (practice on if statement) Q1 :Write a program to read two digit from(0-9), and display them on the next line in manner order Sample execution: Inpu Output of Program: ts Enter the first digit : 9 Enter the second digit : 2 The given digits in manner order are: 2 9 Solution: .MODEL SMALL .STACK 100H .DATA MSG DB 'Enter the first digit:$' MSG1 DB 0DH,0AH, 'Enter the second digit: $' MSG2 DB 0DH,0AH, 'The given digits in manner order:$' .CODE MAIN PROC MOV AX, @DATA MOV DS, AX ; initialize DS MOV AH,9 ; display the string MSG LEA DX, MSG INT 21h ; read first digits and store it in BL MOV AH,1 INT 21h MOV BL,AL ; display the string MSG1 MOV AH,9 LEA DX, MSG1 INT 21h ; read second digits and store it in BH Mov AH,1 INT 21h MOV BH, AL ; Check if the digits are in manner order, ; if not then switch them CMP BL, BH JLE DISPLAY XCHG BL, BH DISPLAY: MOV AH,9 LEA DX, MSG2 INT 21h ; display the string MSG2 ٦ L. Aseel AlDabjan Princess Nora Bint Abdulrahman University Faculty of Computer and Information Science CS 321 :Computer Organization and assembly language First Semester 1432/1433H Lab Model Answers ; display the digits MOV AH, 2 MOV DL, BL INT 21h MOV DL, BH INT 21h ; exit to DOS MOV AH,4CH INT 21H MAIN ENDP end main ٧ L. Aseel AlDabjan
© Copyright 2026 Paperzz