Task Performance
Task Performance
BSEE-3C
- In assembly language, the purpose of the mov is to copy one data file word to its
desired destination like register and memory contents or constant value.
- The first step to mov is Register to Register. It simply copies the contents to other
register source.
- Last is register to memory, the moving data from the register to memory location
means copying the contents into a specific memory location.
• Describe the difference between the add and sub instructions in assembly
language.
- The add means adding of two operands, storing the result in the first operand
wherein both operands may be registers or one operand and one memory
location. While sub performs a difference between first source register’s contents
by the second source.
• How are add and sub used for arithmetic operations on registers or
memory locations?
- For add, is used to add the values of two operands. The result is stored in the
destination operand. The operands can be registers, memory locations, or an
immediate value (a constant). While sub, subtracts the value of the source
operand from the destination operand. The result is stored in the destination
operand. The syntax is like the add instruction.
• Show a simple assembly code snippet using add to add two numbers
stored in registers.
3. Using mov, add, and sub Together:
• Write an assembly code segment that loads a constant value into a register
using mov, adds another value to it using add, and then subtracts a third
value using sub.
• What are the typical limitations or restrictions when using add or sub
instructions in assembly?
- The operands must be same size because you cannot directly add it with different
size.
- You can add or subtract immediate values (constants) to or from registers and
memory, but immediate values are limited to a certain size (typically the same
as the operand size).
- Only one of the operands can be a memory location. You cannot use both
source and destination as memory operands in a single instruction.
- Some assembly languages may have restrictions on using complex addressing
modes directly within an add or sub instruction.
- Some architectures may require memory operands to be aligned to specific
boundaries, and violating these requirements can lead to performance penalties
or exceptions.
4. Memory Operations:
• Explain how memory addressing works with mov, add, and sub.
- In mov, it requires direct and indirect addressing. It can transfer data between
registers, memory, and immediate values with flexible addressing modes. While
in sub and add it can perform arithmetic operations with similar addressing
modes, but only one operand can be a memory location.
• Give an example of loading data from memory into a register using mov.
- When adding and subtracting from memory locations, we can just edit the values
in the registers and then click the single step or step back to change the values
form registers. This will immediately change.
5. Conditional Operations:
• How can you use add or sub instructions to perform conditional arithmetic
(e.g., incrementing or decrementing a value based on a condition)?
- In incrementing, you can use add followed by conditional jump instruction which
transfer control to a different part of the code depending on the given situation.
The add can only be acquired when the ax is greater than the value of the
conditional jump.
- In decrementing condition, you can use sub followed by conditional jump too.
Here, if the value of ax is greater than the given value of conditional jump, it can
jump to the decrement value to bx.
• Describe a scenario where you might use add and sub to manipulate a
counter variable.
- Example is when using loop, where in we register the value of ax to 0, then it will
always be equal to 0.
ACTIVITY NUMBER 3
Prepare and Use the EMU 8086 and insert the CODE
; this example shows the use of aaa instruction (ascii adjust after addition).
; it is used to add huge bcd numbers.
name "bcd_aaa"
org 100h
; al = al + ah =
; = 09h + 05h = 0eh
add al, ah
; store contents of
; ax register:
mov dx, ax
QUESTIONS
• What is the purpose of the aaa instruction in BCD (Binary Coded Decimal)
addition?
- The AAA (ASCII Adjust after Addition) instruction in BCD (Binary Coded Decimal)
addition adjusts the result in the AL register after an addition operation involving
two BCD numbers. Its purpose is to ensure that the result in AL is a valid BCD
number.
• Explain how the aaa instruction adjusts the result of adding two BCD
numbers.
- The AAA instruction (ASCII Adjust After Addition) is used in x86 assembly language
to adjust the result of adding two Binary Coded Decimal (BCD) numbers. BCD is a
way of representing decimal numbers where each digit is encoded separately
using binary.
- When adding two BCD numbers, it's possible for the result to exceed 9 in each
digit, which breaks the BCD representation. AAA is used to correct this. It
examines the least significant nibble (4 bits) of the AL register (which typically
holds the result of addition) and performs the following adjustments:
1. If the least significant nibble of AL is in the range 0 to 9, no adjustment is needed.
2. If the least significant nibble of AL is in the range 10 to 15, it adjusts the AL register
by adding 6 to it and sets the carry flag CF to 1.
3. It adjusts the next higher nibble of AL by adding 1 to it.
- This adjustment ensures that each BCD digit in the result remains within the range
of 0 to 9, making it a valid BCD number.
• In the context of the provided code, why is it necessary to clear the high
byte (ah) before using the aaa instruction?
- The AAA (ASCII Adjust After Addition) adjusts the result in the AL register after an
addition operation to guarantee that ASCII-coded decimal integers are properly
represented. Before utilizing AAA, the high byte (AH register) must be cleared
because AAA only operates on AL, which may contain useless data. Clearing AH
guarantees that only AL influences the outcome of the AAA instruction, preserving
the ASCII representation of decimal integers.
-
a. How does the assembly code convert the BCD result (14) into ASCII
characters for display?
- It separates the digits which isolates the tens and ones digits, convert it to ASCII
characters/equivalent by adding the ASCII code for 0 to digit value and lastly,
storing the ASCII characters by representing tens and ones digits in memory or
registers.
b. Explain the significance of using or dh, 30h and or dl, 30h before
converting and printing the BCD digits.
- Using OR DH, 30h and OR DL, 30h in assembly language before converting and
printing BCD digits serves to convert the binary-coded decimal (BCD) digits into
their corresponding ASCII characters.
- Converting to ASCII: In ASCII, the character '0' represents the hexadecimal value
30h. By using a bitwise OR operation with 30h, the BCD digits stored in the DH
(tens digit) and DL (ones digit) registers are effectively translated into their ASCII
equivalents. For example, if DH has the BCD value 1, OR-ing it with 30h yields 31h,
which is the ASCII character '1'. Similarly, if DL has the BCD value 4, OR-ing it with
30h yields 34h, which is the ASCII character '4'.
- It must also be compatible with the display making it easier to print the digits on
the screen.
c. Which BIOS interrupt (int 10h) function is used to display characters on the
screen in this code?
- In this code, the BIOS interrupt 10h is most likely used to display characters on the
screen. Specifically, the function AH = 0x0E of interrupt int 10h is frequently
utilized for this reason. This function displays a character in teletype (TTY) mode,
which displays characters on the screen according to their ASCII values. It is
commonly used for simple text output in DOS and BIOS-based systems.
a. Why does the code wait for a key press (int 16h) at the end?
- The code most likely waits for a key press at the end utilizing interrupt int 16h to
interact with the user or pause execution before quitting. This allows the user to
see the output on the screen before the program is terminated. Waiting for a key
press ensures that the application does not exit instantly and gives the user
control over when it terminates by pushing any key. It is a typical practice in
command-line or assembly language applications where user involvement is
minimal, to ensure that the output is not lost before the user has a chance to view
it.
b. What would happen if the wait for a key press (int 16h) was omitted from
the code?
- If the wait for a key press (int 16h) was omitted from the code, the program would
likely terminate immediately after displaying the output without giving the user a
chance to view it. This means the output would flash briefly on the screen, and the
program would exit abruptly, making it difficult for the user to observe the results.
Omitting the wait for a key press would result in an undesirable user experience,
especially in command-line programs or assembly language programs where user
interaction is expected or desired.
c. How would you modify this code to handle input of the BCD numbers from
the user before performing the addition and displaying the result?
- To modify the code to handle input of the BCD numbers from the user before
performing the addition and displaying the result, you would need to incorporate
input routines to read user input and convert it to BCD format.
- You must first prompt the user for input to enter BCD numbers. Implement input
routines to read user input from the keyboard. You can use BIOS interrupt int 16h
for this purpose, typically with function AH = 0 for reading a single character at a
time and convert the characters to their corresponding BCD representation. Add
the 2 BCD numbers then convert to ASCII. Then wait for a key before exiting the
program.