Question:
SubmitDesignaDocumenttypeddescriptionSecificationsofthealgorithm you will use to solve the problem. Use words and be descriptive – what I’m looking for here is that you know how the assembler works and that you are comfortable working with it. This should be written in paragraph from.
Example questions you might answer:
- • How will you convert the two “digit” ASCII input into a two digit number?
- • How will you deal with looping (since assembly gives no or )?
- • What are your loop conditions and why (i.e. when will youwhileexit theforloop)
- You can use the following algorithm to compute the sum.
int compute_sum (int n)
{
sum = 0;
i = 1;
while (i <= n)
{
sum = sum + i*i;
i = i + 1;
}
}
Answer:
To use the program:
Read your source program: | ||
1. | From the menu: File à Open | or |
2. | Simply copy and paste your program to the text box under ‘Source Program’ | |
Compile your program:
From the menu: Tools à Compile
Run your program:
From the menu: Tools à Execute à Run or Walk (step by step). Values of registers and memory will be shown.
Inputs/Outputs:
If your program uses INPR to read inputs, you can type the inputs in the “input Stream” text box. Outputs from OUTR will be shown in Output Stream.
Review of Instructions
There are three groups of instructions in this assembler:
- Memory Reference Instructions
- Non memory Reference Instructions
- Pseudo Instructions (i.e., Assembler directive instructions)
- Memory Reference Instructions (MRI)
Direct Addressing: opcode operand e.g., ADD num Memory word at location ‘num’ is added to accumulator AC. i.e., AC = AC + M[num];
Here, effective address of the operand is ‘num’
Indirect Addressing: opcode operand I e.g., ADD num I Memory word of memory word at location ‘num’ is added to AC. i.e., AC = AC + [M[num]]
Here, effective address of the operand is M[num].
MRI Instructions: (In the following, ‘eee’ denotes effective address.)
AND xxx AND xxx I
Logical AND of effective memory word to AC
i.e., AC = AC and M[eee];
ADD xxx ADD xxx I
Add effective memory word to AC.
i.e., AC = AC + M[eee];
LDA xxx LDA xxx I
Load effective memory word to AC.
i.e., AC = M[eee];
STA xxx STA xxx I
Store content of AC to effective memory word.
i.e., M[eee] = AC;
BUN xxx BUN xxx I
Branch, unconditionally, to effective address.
i.e., PC = eee;
BSA xxx BSA xxx I
Address of next instruction (i.e., PC) is stored in effective memory word.
Then, execute the instruction following the effective address.
i.e., M[eee] = PC; PC = eee + 1;
Note: BSA is useful to save the return address and to branch to a procedure.
ISZ xxx ISZ xxx I
Increment memory word. If incremented value is 0, increment PC (i.e., skip next instr). i.e., M[eee] = M[eee] + 1; if (M[eee] == 0) PC = PC + 1; Note: ISZ is used to count iterative loops.
- Non Memory Reference Instructions
These instructions do not have the operand part or the addressing mode.
CLA
Clear AC
CLE
Clear E, the extended bit of AC
CMA Complement AC
CME
Complement E
CIR
Circular shift to the Right on AC and E
CIL
Circular shift to the Left on AC and E
INC
Increment AC
SPA
Skip next instruction, if AC is Positive, i.e., if (AC > 0) PC = PC + 1;
SNA
Skip next instruction, if AC is Negative, i.e., if (AC < 0) PC = PC + 1;
SZA
Skip next instruction, if AC is Zero, i.e., if (AC == 0) PC = PC + 1; (Note: SPA, SNA, and SZA are used in conditional branching.)
SZE
Skip next instruction, if E is Zero, i.e., if (E == 0) PC = PC + 1;
HLT
Halt the execution
INP
Input a character from INPR to low-order bits of AC
OUT
Output a character from low-order bits of AC to OUTR
SKI
Skip on Input flag
- Pseudo Instructions
ORG hhh Instruction listed in the following line wll be placed at address ‘hhh’ (Hex)
DEC n Decimal number ‘n’ will be placed in the memory word
HEX n Hexadecimal number ‘n’ will be placed in the memory word END Denotes the end of assembly language source program
SUM OF SQUARES OF SERIES
Code Flow is explained below.
- The attributes used for implementing sum of series of squares are model small
- Data, operator 1, operator 2 and the final result.
- Initially, the data is moved to ax registor. The value in the ax registor is then moved to ds. The operator performs its operations in ax valuae and the operator 2 performs its operation in bx value.
- Then ax and the value in bx is added with the help of operands for sum up and finding the squares.
- The value is again stored in ‘di’ from the offset result.
- The value from ax is nw stored in di address. The value 09h is moved to ah. The int value given is 21h. finally the program ends.
The above is the code which is run in the emulator
The code is performing step by step procedure and the value of AX,BX,CX and provided.
The message dialog box shows the address value.
The output displays the result which performs two operations such as summing up the values and squaring it.