solution programming handcoding comanlises

5
8/20/2019 Solution Programming Handcoding Comanlises http://slidepdf.com/reader/full/solution-programming-handcoding-comanlises 1/5  QUESTIONS: 1. Supply the appropriate instruction for the given program to accomplish the given task. 3010h - 20h + (20h * 40h) - (100h / 40h) PROGRAM: XOR AX, AX; to clear register AX, XOR is used for 16-bit size of info  XOR CX, CX (1);to clear register CX, XOR is used for 16-bit size MOV CL, 40H; to move 40 hexa into the register CL  PLUS:  ADD AX, 20H (2); to add register AX content with 0020 hexa  DEC CL; to subtract 1 from CL content  JNZ PLUS (3) ;to check if CL is not yet equal to zero, and if true, it will go to PLUS and execute ADD AX, 20H again. MOV BX, 3010H; to move 3010 hexa to register BX   ADD AX, BX; to add content of register AX with the content of register BX  PUSH AX (4); to put the result of the instruction ADD AX,BX unto the stack  XOR AX, AX; to clear register AX, XOR is used for 16-bit size of info  XOR BX, BX; to clear register X, XOR is used for 16-bit size of info  XOR CX, CX OR MOV AX, 0100H(5)  ; to clear register CX, XOR is used for 16-bit size of info OR move data 0100 hexa into register AX  MOV BX, 0040H; to move 0040 hexa into register BX  MOV AX, 0100H OR XOR CX, CX(6)  ; to move 0100 hexa into register AX or clear register CX, XOR is used for 16-bit size of info  MINUS: SUB AX, BX; to subtract BX content from AX, the result will be stored in register AX  INC CL (7) ; to add 1 to the content of register CL  CMP AX, 0H; to compare register AX content to zero, if not equal to zero zero flag will remain the same, if equal to zero, zero flag will become 1  JNZ MINUS; to compare zero flag if equal to 1, if yes it will go to the MINUS and execute the instruction SUB AX, BX otherwise, the next instruction will be executed.  MOV DL, 20(8) ; to move 20 hexa into register DL   ADD DL, CL ; to add content of register DL with the content of the register CL, the result will be stored into the register DL  XOR AX, AX; to clear register AX, XOR is used for 16-bit size of info  POP AX (9) ; to save the current content of register AX unto the stack, assuming stack is empty  MOV DH, 0H; to load 0 hexa to register DH  SUB AX, DX (10) ; to subtract the content of register DX from the content of register AX  

Upload: aelle00

Post on 07-Aug-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Solution Programming Handcoding Comanlises

8/20/2019 Solution Programming Handcoding Comanlises

http://slidepdf.com/reader/full/solution-programming-handcoding-comanlises 1/5

 

QUESTIONS:

1.  Supply the appropriate instruction for the given program to accomplish the giventask.

3010h - 20h + (20h * 40h) - (100h / 40h)

PROGRAM:

XOR AX, AX; to clear register AX, XOR is used for 16-bit size of info  XOR CX, CX (1);to clear register CX, XOR is used for 16-bit size

MOV CL, 40H; to move 40 hexa into the register CL  PLUS:  ADD AX, 20H (2);  to add register AX content with 0020 hexa  

DEC CL; to subtract 1 from CL content  JNZ PLUS (3) ;to check if CL is not yet equal to zero, and if true, it will go to PLUS

and execute ADD AX, 20H again. 

MOV BX, 3010H; to move 3010 hexa to register BX   ADD AX, BX; to add content of register AX with the content of register BX  

PUSH AX (4); to put the result of the instruction ADD AX,BX unto the stack  XOR AX, AX; to clear register AX, XOR is used for 16-bit size of info  XOR BX, BX; to clear register X, XOR is used for 16-bit size of info  XOR CX, CX OR MOV AX, 0100H(5) ; to clear register CX, XOR is used for 16-bit

size of info OR move data 0100 hexa into register AX  

MOV BX, 0040H; to move 0040 hexa into register BX  MOV AX, 0100H OR XOR CX, CX(6) ; to move 0100 hexa into register AX or

clear register CX, XOR is used for 16-bit size of info  MINUS: SUB AX, BX; to subtract BX content from AX, the result will be stored in register AX  

INC CL (7) ; to add 1 to the content of register CL  CMP AX, 0H; to compare register AX content to zero, if not equal to zero zero flag will

remain the same, if equal to zero, zero flag will become 1  JNZ MINUS; to compare zero flag if equal to 1, if yes it will go to the MINUS and

execute the instruction SUB AX, BX otherwise, the next instruction will be executed. MOV DL, 20(8) ; to move 20 hexa into register DL  

 ADD DL, CL ; to add content of register DL with the content of the register CL, the

result will be stored into the register DL  XOR AX, AX; to clear register AX, XOR is used for 16-bit size of info  POP AX (9) ; to save the current content of register AX unto the stack, assuming

stack is empty  MOV DH, 0H; to load 0 hexa to register DH  

SUB AX, DX (10) ; to subtract the content of register DX from the content ofregister AX  

Page 2: Solution Programming Handcoding Comanlises

8/20/2019 Solution Programming Handcoding Comanlises

http://slidepdf.com/reader/full/solution-programming-handcoding-comanlises 2/5

 

LINE

 NO.

AX BX CX

CHCL

DX STACK

1 0000

2 0000

3 0040

4 0020

5 003F

0040 003D

0060 003E

0080 003D

00A0 003C

00C0 003B

00E0 003A

0100 0039

0120 0038

0140 0037

0160 00360180 0035

01A0 0034

01C0 0033

01E0 0032

0200 0031

0220 0030

0240 002F

0260 002E

0280 002D

02A0 002C

02C0 002B

02E0 002A0300 0029

. 0028

. .

. .

. .

. .

. .

0760 0006

0780 0005

07A0 0004

07C0 000307E0 0002

0800 0001

0000

7 3010

8 3810

9 3810 

10 0000

11 0000

Page 3: Solution Programming Handcoding Comanlises

8/20/2019 Solution Programming Handcoding Comanlises

http://slidepdf.com/reader/full/solution-programming-handcoding-comanlises 3/5

 

12 0000

13 0040

14 0100

00C0 0001

0080 0002

0040 0003

0000 0004

15 20

16 24

17 0000

18 3810

19 0024

20 37EC

ANSWER:

AX=37ECBX=0040

CX=0004DX=0024

STACK=NONE

Page 4: Solution Programming Handcoding Comanlises

8/20/2019 Solution Programming Handcoding Comanlises

http://slidepdf.com/reader/full/solution-programming-handcoding-comanlises 4/5

 

INSTRUCTION CONTENT/S ADDRESS/ESMOV AX, 1234HMOV DS, AXMOV SI, 0400HMOV DI, 0500HMOV CX, 000A

BACK: MOV AX, [SI]MOV [DI], AXINC SIINC DIDEC CXJNZ BACKHLT 

B8 34 128E D8

BE 00 04BF 00 05B9 0A 00

8B 0489 05

464749

75F7F4

0000-00020003-00040005-00070008-000A000B-000D000E-000F0010-0011

001200130014

0015-00160017

MOV AX, 1234 1011 W REG DATA

1011 1 000 3412== B83412

SR R/M

MOV DS, AX 10001110 MOD 0 SR R/M10001110 11 0 11 000== 8ED8

MOV SI, 0400 1011 W REG DATA

1011 1 110 0004== BE0004

MOV DI, 0500 1011 W REG DATA1011 1 111 0005 == BF0005

MOV CX, 000A 1011 W REG DATA1011 1 001 0A00 == B90A00

REG R/MMOV AX, [SI] 100010 D W MOD REG R/M

100010 1 1 00 000 100== 8B04

R/M REGMOV [DI], AX 100010 D W MOD REG R/M

100010 0 1 00 000 101 == 8905

INC SI 01000 REG01000 110 == 46 

INC DI 01000 REG01000 111 == 47 

DEC CX 01001 REG

01001 001 == 49 

Page 5: Solution Programming Handcoding Comanlises

8/20/2019 Solution Programming Handcoding Comanlises

http://slidepdf.com/reader/full/solution-programming-handcoding-comanlises 5/5

 

JNZ BACK 01110101 DISP

01110101 ==75 F7 PL=0015

DL=000EBACKWARD BRANCHINGDL=PL+2-X

000E=0015+2-X

X=0017-000EX= 0009; GET THE 2’S COMPLENT 

X= FFFF-0009=FFF6+1=FFF7

LOWER DISPLACEMENT =F7

HIGHER DISPLACEMENT = FF

FORWARD BRANCHING (PL<DL)

DL=PL+2+X

BACKWARD BRANCHING (PL>DL)DL=PL+2-X

WHERE:X=DISPLACEMENT

DL=DESTINATION LOCATION

PL=PRESENT LOCATION

2= BECAUSE MOST OF THE JUMP INSTRUCTIONS ARE TWO-BYTE SIZE*TAKE NOTE THAT THERE ARE 3-BYTE SIZE JUMP INSTRUCTIONS

HLT 11110100 == F4