0% found this document useful (0 votes)
33 views5 pages

Handcoding Instructions for AX Register

The document provides instructions for a program to perform the calculation 3010h - 20h + (20h * 40h) - (100h / 40h). It includes: 1) Instructions to clear registers, add values to registers, and loop to multiply 20h by 40h 2) Instructions to add the result to 3010h and push to the stack 3) Instructions to divide 100h by 40h, subtract from the running total, and add the remainder to 20h 4) The final value is subtracted from the stack and stored in AX

Uploaded by

aelle00
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

Handcoding Instructions for AX Register

The document provides instructions for a program to perform the calculation 3010h - 20h + (20h * 40h) - (100h / 40h). It includes: 1) Instructions to clear registers, add values to registers, and loop to multiply 20h by 40h 2) Instructions to add the result to 3010h and push to the stack 3) Instructions to divide 100h by 40h, subtract from the running total, and add the remainder to 20h 4) The final value is subtracted from the stack and stored in AX

Uploaded by

aelle00
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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
PLUS:

MOV CL, 40H; to move 40 hexa into the register CL

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.
3010H; to move 3010 hexa to register BX

MOV 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
MINUS:

clear register CX, XOR is used for 16-bit size of info


to subtract BX content from AX, the result will be stored in register AX

SUB AX, BX;


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
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

JNZ MINUS;

ADD DL, CL ;
XOR AX, AX;
POP AX (9) ;

to add content of register DL with the content of the register CL, the
result will be stored into the register DL
to clear register AX, XOR is used for 16-bit size of info

to save the current content of register AX unto the stack, assuming


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

MOV DH,
SUB AX, DX (10) ;

to subtract the content of register DX from the content of


register AX

LINE AX
NO.
1
0000
2
3
4
0020
5
0040
0060
0080
00A0
00C0
00E0
0100
0120
0140
0160
0180
01A0
01C0
01E0
0200
0220
0240
0260
0280
02A0
02C0
02E0
0300
.
.
.
.
.
.
0760
0780
07A0
07C0
07E0
0800
7
8
9
10
11

BX

CX
DX
CHCL

STACK

0000
0040
003F
003D
003E
003D
003C
003B
003A
0039
0038
0037
0036
0035
0034
0033
0032
0031
0030
002F
002E
002D
002C
002B
002A
0029
0028
.
.
.
.
.
0006
0005
0004
0003
0002
0001
0000
3010

3810
3810
0000
0000

12
13
14

15
16
17
18
19
20

0000
0040
0100
00C0
0080
0040
0000

0001
0002
0003
0004
20
24

0000
3810
0024
37EC

ANSWER:
AX=37EC
BX=0040
CX=0004
DX=0024
STACK=NONE

INSTRUCTION

BACK:

MOV AX, 1234H


MOV DS, AX
MOV SI, 0400H
MOV DI, 0500H
MOV CX, 000A
MOV AX, [SI]
MOV [DI], AX
INC SI
INC DI
DEC CX
JNZ BACK
HLT

MOV AX, 1234


SR R/M
MOV DS, AX

CONTENT/S

ADDRESS/ES

B8 34 12
8E D8
BE 00 04
BF 00 05
B9 0A 00
8B 04
89 05
46
47
49
75F7
F4

0000-0002
0003-0004
0005-0007
0008-000A
000B-000D
000E-000F
0010-0011
0012
0013
0014
0015-0016
0017

1011 W REG DATA


1011 1 000 3412== B83412
10001110 MOD 0 SR R/M
10001110 11 0 11 000== 8ED8

MOV SI, 0400

1011 W REG DATA


1011 1 110 0004== BE0004

MOV DI, 0500

1011 W REG DATA


1011 1 111 0005 == BF0005

MOV CX, 000A

1011 W REG DATA


1011 1 001 0A00 == B90A00

REG R/M
MOV AX, [SI]

R/M REG
MOV [DI], AX

100010 D W MOD REG R/M


100010 1 1 00 000 100== 8B04

100010 D W MOD REG R/M


100010 0 1 00 000 101 == 8905

INC SI

01000 REG
01000 110 == 46

INC DI

01000 REG
01000 111 == 47

DEC CX

01001 REG
01001 001 == 49

JNZ BACK

01110101 DISP
01110101 ==75 F7

PL=0015
DL=000E
BACKWARD BRANCHING
DL=PL+2-X
000E=0015+2-X
X=0017-000E
X= 0009; GET THE 2S 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

Common questions

Powered by AI

Immediate values, such as '40H' loaded into CL, directly influence the control flow by determining the number of times a loop executes. Labels like 'PLUS' and 'MINUS' serve as targets for branch instructions (e.g., JNZ), facilitating loop control by directing the program to iterate sections of code based on conditional evaluations. These mechanisms ensure precise control over execution paths, leveraging direct register manipulation and condition checks to structure program logic effectively, allowing complex operations and conditional loops to operate flexibly and efficiently .

The stack in the program plays a critical role in temporarily storing values to preserve processor state or save intermediate computational results. The program uses 'PUSH AX' to save the result of the addition of AX and BX to the stack and 'POP AX' to retrieve this value from the stack into AX later in the sequence. This mechanism is vital for managing local variables, function calls, and recursive procedures without corrupting the values in registers that might be needed again later .

The loop structure begins with clearing the AX register and using the instruction 'MOV CL, 40H' to load the constant 40H into CL. The loop labeled 'PLUS' executes the instruction 'ADD AX, 20H', which adds 20H to AX, followed by 'DEC CL' to decrement CL. The loop iterates while 'JNZ PLUS' keeps checking if CL is not zero, re-executing the addition until CL reaches zero. The final result of AX will be a cumulative sum of 20H added 40 times, equaling 800H .

The XOR operation in assembly programming is used to clear a register by performing a bitwise XOR of the register with itself, resulting in zero. In this program, 'XOR AX, AX' is used at multiple points to ensure that the register AX is reset to zero, effectively clearing it before any new arithmetic operations are performed. This is useful for maintaining data integrity and preventing unintended data from affecting subsequent computations .

The subtraction in the program is implemented with the instruction 'SUB AX, BX', which subtracts the content of BX from AX and stores the result in AX. A loop labeled 'MINUS' is initiated, where 'INC CL' increments CL, and 'CMP AX, 0H' compares the result in AX with zero. The condition 'JNZ MINUS' ensures the loop continues if AX is not zero, continually subtracting the value in BX from AX until AX equals zero, at which point the zero flag is set and the loop terminates, ensuring any negative results are handled properly by effectively zeroing out AX .

Incrementing (e.g., 'INC CL') and decrementing (e.g., 'DEC CL') instructions within loops are crucial in scenarios requiring iterative processes. They control the loop's lifespan by modifying a counter register used in conditional checks, such as 'JNZ'. This regulates the number of iterations, impacting execution by ensuring loops repeat only as necessary, optimizing program performance, preventing infinite loops, and enabling controlled iterative computation crucial for tasks like sequence processing, algorithm implementation, and resource management .

The final state of registers shows that AX equals 37EC, BX equals 0040, CX equals 0004, and DX equals 0024, with the stack being empty. This outcome indicates successful computation as the operations have concluded with expected results reflecting accurate arithmetic and moving operations from the logic implemented. Specifically, the final AX value of 37EC hints at successful completion of arithmetic and loop operations, demonstrating effective use of register manipulations and control flows throughout execution, achieving the intended program goals without data or control anomalies .

Data movement in this program is managed through a combination of 'MOV' instructions and loop constructs. For example, 'MOV AX, [SI]' transfers data from memory at the address SI to AX, and 'MOV [DI], AX' moves the data from AX to memory at DI. This process occurs inside a loop labeled 'BACK', where instructions 'INC SI' and 'INC DI' ensure that SI and DI are incremented each time, facilitating sequential data copying of blocks of memory, essential for operations like buffer transfers and data manipulation in segments, enhancing processing efficiency in loops .

Setting and clearing flags during operations like subtraction are crucial as they determine the flow of subsequent conditional instructions. In subtraction, the zero flag is affected as it indicates whether the result is zero ('CMP AX, 0H'). Subsequent instructions, like conditional branching ('JNZ MINUS'), depend on these flags to decide execution flow (e.g., repeating a loop or terminating it), significantly affecting program logic, control flow, and ensuring that processes like error-checking or state transitions are effectively handled .

Loop constructs in the code are managed using decrement and conditional branch instructions formatted in a systematic way. The common pattern involves initializing a counter register (e.g., 'MOV CL, 40H'), performing a computational instruction (e.g., 'ADD AX, 20H'), decrementing the counter ('DEC CL'), and using a zero-check conditional jump ('JNZ') to repeat the loop until conditions are met. This pattern ensures structured repetitive code execution, effectively facilitating operations like multiplications or accumulations and ensuring program logic follows a controlled sequence until specific conditions are filled .

You might also like