Chapter 3, 4 Exercises Preparation for the Quiz 2

Assembly Language, CSCI264

Chapter 3, 4 – Exercises – Preparation for the Quiz 2

1.  What flags will be set and what flags will be cleared after the execution of the following commands:

a.  MOV AL, -123 b. MOV AL, 200 c. MOV AL, 064H

MOV CL, -4 MOV CL, 4 ADD AL, 100

CMP CL, AL DEC CL

CMP AL, CL

d. MOV BH, -56 e. MOV BL, 12 f. MOV BH, 5

SUB BH, 128 MOV AL, 250 MOV AL, 16

SUB AL, BL MUL BH

g. MOV AX, 15

MOV BL, 6

MUL BL

2.  What will be the output of the following program if the input is:

a. 6 and 2 b. 7 and 3 c. 2 and 7

MOV EDX, 0

IN AL, [DX]

MOV BL, AL

IN AL, [DX]

MOV ECX, 0

RPT: INC ECX

SUB BL, AL

JNS RPT

DEC ECX

ADD BL, AL

MOV EDX, 1

MOV EAX, ECX

OUT [DX], EAX

MOV AL, BL

OUT [DX], AL

RET

3.  What will be the output of the following program?

MOV AL, 56

MOV BL, 43

CMP BL, AL

JB BIS

MOV AL, 1

JMP END

BIS: MOV AL, 2

END: MOV EDX, 1

OUT [DX], AL

4. What will be the output of the following program?

MOV AL, 40

MOV BL, 40

CMP BL, AL

JNE BIS

MOV AL, 1

JMP END

BIS: MOV AL, 2

END: MOV EDX, 1

OUT [DX], AL

5.What will be the output of the following program?

MOV AL, 40

MOV BL, 40

CMP BL, AL

JNA BIS

MOV AL, 1

JMP END

BIS: MOV AL, 2

END: MOV EDX, 1

OUT [DX], AL

6.  What will be the output of the following program, if the input is:

  1. 7 and 4 b. 5 and 3

MOV EDX, 0

IN AL, [DX]

MOV BL, AL

IN AL, [DX]

CMP BL, AL

JA SOS

MOV AL, 2

JMP FIN

SOS: MOV AL, 1

FIN: MOV EDX, 1

OUT [DX], AL

RET

Explain what this program is doing.

7.  What will be the output of the following program, if the input is:

a. 5 b. 7 c. 2

MOV EDX, 0

IN AL, [DX]

MOV BL, AL

MOV AL, 1

MOV ECX, 3

DOM: MUL BL

DEC ECX

JNZ DOM

MOV EDX, 1

OUT [DX], AX

Explain what this program is doing?

8. What will be the output of the following program?

MOV AX, 15

MOV BL, 4

DIV BL

CMP AH, 2

MOV EDX, 1

JB FIN

OUT [DX], AL

JMP END

FIN: MOV AL, AH

OUT [DX], AL

END: RET

Explain what this program is doing?

9.  What will be the output of the following program, if the input is: a. 5 3 b. 80 80

MOV EDX, 0

IN AL, [DX]

MOV BL, AL

IN AL, [DX]

CMP BL, AL

JE SOS

MUL AL

JMP FIN

SOS: MUL BL

FIN: MOV EDX, 1

OUT [DX], AX

RET

10.  Write an Assembly Language program that will read three positive integers and will calculate the following values:

(num1*num2) / num3

and

(num1*num2 ) % num3

11.  Write an Assembly language program that will read a positive integer and check if the input number is even or odd. If the input is even the program will output 0, otherwise the program will output 1.