Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
URSM-COLLEGE OF ENGG.
1/6
b
-
h
b b
NV UP
OV DN
O
D
h
b b
b b b
DI T PL NZ EI T NG ZR I
T S
Z
h
b
NA
AC
A
b
-
b
PO
PE
P
(0) No oVerflow
(1) OVerflow
b
-
b
NC
CY
C
No Carry
CarrY
(0) UP increment
(1) DowN (decrement)
Parity Odd
Parity Even
No Auxiliary carry
Auxiliary Carry
(0) PLus
(1) NeGative
No Zero
ZeRo
NOTE: T (trap) enables trapping through an on-chip debugging feature (programenabled error trapping); if enabled (1) the P interrupts the flow of the program on
conditions as indicated by the debug/control registers, otherwise it is disabled.
-rip
IP hhhh
:0100
-g
The other way is to specify a starting point as part of the g command like
-g =0100
When you use the go command, the processor has to know where to stop. An assembly
program must terminate using RET (return) command or the MS-DOS interrupt function
INT 20 to stop program execution and return to DEBUG prompt.
FMFernando
7/28/11
MP SYSTEMS
URSM-COLLEGE OF ENGG.
2/6
HEX Addition
1. For example, the assembly program to add 49H (or decimal 73) and 1EH (decimal 30)
may be as follows:
xxxx:0100 MOV AL,49
xxxx:0102 ADD AL,1E
xxxx:0104 RET
;store dec 73
;add dec 30
;(or replace RET with INT 20)
Using DEBUGs go command with starting and stopping or breakpoint 0100 to 0104
prior to executing the RET (or INT 20) command at 0104, enter
-g =0100 0104
These will cause program execution to start at address 0100H and to stop at address
0104H. The contents of the register and flags will be automatically displayed. The same
task can be accomplished (only if IP is set at address 0100H) using
-g 0104
-rf
Examining the flags from right to left; (NC) means there was no carry from the 8th (the
MSB of low byte) to the 9th bit (the LSB of the high byte). The result (if converted to
binary 0110 1110) was parity odd (PO) since it has odd number of 1s. There was an
auxiliary carry (AC) that is, from 4th to 5th bit (which is also very useful in BCD
numbers). There was no zero (NZ) because the answer was not zero. The answer was
positive or plus (PL) because there was no 1 in the 8 th bit. (EI) enable interrupt
request and the auto-increment (UP) are used by the DI and/or SI registers during string
instructions. There was no overflow (NV) or out of range; for 8-bit signed binary
numbers the range is -128 to +127. Note that if you compare the flag bits before and after
program run, a change was only in auxiliary carry (AC) flag.
2. Assemble and run the following program in DEBUG. The flag bit that will change
should be the zero flag that is from an initial state (NZ) to (ZR).
xxxx:0100 MOV AL,C9 ;negative 55
xxxx:0102 ADD AL,37 ;positive 55 is added
xxxx:0104 RET
-g 104
-rf
FMFernando
7/28/11
MP SYSTEMS
URSM-COLLEGE OF ENGG.
3/6
3. Since the valid 8-bit range is +127 to -128 and for 16-bit range, +32767 to -32,768.
Modify your previous program for 8-bit overflow range: 123 + 111 = 234 in decimal
notation. In hex, 7B + 6F = EA. There will be an auxiliary carry (AC), a negative sign
bit (NG), and that the overflow (OV) bit is set. The sum in hex (EA) is the correct answer
if you are using unsigned binary numbers! For signed binary numbers hex EA in decimal
is -22 and this is not the correct answer since it exceeded the 8-bit signed binary
numbers.
A sample program interaction is shown.
BCD Addition
Because of differences in the way binary and decimal numbers round, and because
numeric output to humans is usually decimal, it is sometimes helpful to do addition using
binary coded decimal. The processor encounters problems with BCD addition but this is
corrected or adjusted by way of packed BCD numbers using the command decimal
adjust (DAA). See the following example.
1. Decimal (BCD)
0100 0111 (BCD)
+ 0011 0110 (BCD)
1000 0011 (BCD)
4710
3610
8310
2. Binary/Hex
0100 0111
+ 0011 0110
=
0111 1101
4716
3616
7D16
Next, execute the program at the DEBUG prompt using this instruction:
-g =0100 011B
FMFernando
7/28/11
MP SYSTEMS
URSM-COLLEGE OF ENGG.
4/6
Pay attention to the final contents of AX = 0083 (this is the result of BCD addition) and
BX = FA92 including the status registers. Other important information specially prior to
these can be shown using the dump (d) command starting at RAM address 0140 until
01AF by entering:
-d 01A0 01AF
Screen output should be
XXXX:01A0 7D 06 72 83 92 72 00 00-00 00 00 00 00
These means
RAM Address 01A0
RAM Address 01A1
RAM Address 01A2
RAM Address 01A3
RAM Address 01A4
RAM Address 01A5
binary/HEX sum = 7D
binary/HEX flags (low byte) = 06
binary/HEX flags (high byte) = 72
BCD sum = 83
BCD flags (low byte) = 92
BCD flags (high byte) = 72
To decode the flag bits consider RAM address 01A5 and 01A4 in the high-byte and lowbyte sequence. This is equivalent to
Hex
Bin
0
1
7
0
-
1
-
1
-
1
-
2
1
NA
AC
0
-
0
PO
PE
1
-
0
NC
CY
This means flags affected are NV, UP, EI, NG, NZ, AC, PO, and NC.
Subtraction
Subtraction is the opposite of addition and can be done using the SUB command as
follows:
xxxx:0100 MOV AL, 7F
xxxx:0102 SUB AL, 80
xxxx:0104 RET
The sample program interaction follows:
FMFernando
7/28/11
MP SYSTEMS
URSM-COLLEGE OF ENGG.
5/6
FFE2
12D3
12D0 CB46
Integer Division
When division is done, the dividend must be twice as wide (16 or 32 bits) as the divisor
(8 or 16 bits). Suppose 564A (dividend) is divided by FB (divisor) the result in integer
format is 58 (the quotient) found in AL and the remainder 2, is found in AH. Use the
following code:
MOV AX 564A
MOV BL,FB
DIV BL
RET
Another example is:
MOV DX,20E2
MOV AX,8DF4
MOV BX,45CE
DIV BX
RET
FMFernando
7/28/11
MP SYSTEMS
URSM-COLLEGE OF ENGG.
6/6
PROBLEM:
1. With a computer and DEBUG utility program, store the unsigned hex 67 and 23 in
two consecutive RAM address. Write an assembly code to find the sum of these two
numbers and store the result in a free RAM address. (HINT: One possibility is first use
the DEBUG enter e command as in -e 0180 67 23 00 00 to place 67,
23, 00, 00 into RAM address 0180,
respectively. Then assemble and run the appropriate code to solve this problem.)
2. Determine which flags are altered by subtracting the signed hex 4D from 7F. Write a
program to store all values required including flag registers in appropriate RAM
addresses.
3. Divide 12D0CB46 by FFE2 and show on-screen the computed value.
4. Store in RAM the hex value 20E28DF4 as the dividend to find the quotient when
FMFernando
7/28/11