Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Assembly Language Programming

Name: Anonymous 2013-04-02 23:58

Microprocessor Concepts and Assembly Language Programming

Objectives:

• Get familiar with the structure of an assembly language program.
• Use instructions to construct loops for a simple algorithm.

• Use DOS interrupts (or service routines) for basic I/O operations.

•Use proper instructions to do basic calculation and check for overflow.

Develop on paper the algorithm and draw the corresponding flowchart for the program below:

Define an array of any 20 arbitrary 8-bit unsigned numbers in the Data Segment. Determine the sum of all odd numbers and the sum of all even numbers. Compare and determine if the sum of all odd numbers is larger than, equal to or smaller than the sum of all even numbers. Print a proper message on the screen based on the result.

Hints:

• As you enter a key, say „1‟, in the keyboard, the ASCII code of „1‟ will be read in. Likewise, if you output a key say „1‟ to the monitor, you have to output the ASCII code of „1‟ to the monitor, not „1‟ itself.

• The ASCII code of keys can be viewed using:

Helppc -> Uncategorized/Miscellaneous Topics -> ASCII under column 3, and column 4 or 6.
The ASCII codes of 0, 1, … , 9 are 30h, 31h, …, 39h.
The ASCII codes of A, B, …, Z are 41h, 42h, …, 5Ah.
The ASCII codes of a, b, …, z are 61h, 62h, …, 7Ah.
The ASCII codes of LF (line feed) is 0Ah, CR (carriage return) is 0Dh, and ESC-key is 1Bh.

• As a character such as 'A' is entered at the keyboard, the INT 21h,7 can be invoked to obtain the ASCII code of 'A' in the AL register. That is AL <= 41h. Here is how to use.

First, you set up a loop with the following lines:

MOV AH, 7

INT 21h

As soon as you enter key 'A' at the keyboard, the value 41h will be stored in AL. Thus, you can store this value right away, into a register or a memory location:

MOV BL, AL

BL now has 41h.

• The Interrupt such as INT 21h, 7 can be viewed using
Helppc -> Interrupt Services DOS-BIOS-EMS-Mouse -> int a, b where a is the interrupt number and b is the service number. In this case, 21h is the interrupt number, and 7 is the service number. Both a and b are hexadecimal numbers.

• If you want to display a character such as 'A' on the monitor, you need to place the ASCII code of 'A' that is 41h on DL register, before invoking the INT 21h, 2. Here is how to use.

MOV DL, 41h

MOV AH, 2

INT 21h

As soon as INT 21h is invoked, the monitor will display 'A' at its current cursor position.

• INT 21h, 9 is used to display a string on the monitor, whereas INT 21h, 4Ch is used to terminate the program normally. Refer to HELPPC for detailed descriptions.

• The oddity of numbers could be checked by bit-wise “AND” instruction or “TEST” instruction. Refer to HELPPC or an instruction manual for the detailed description of these instructions.

• Be careful of data width and overflow. The sum of 8-bit numbers can easily be greater than 255. Thus, you may use WORD variables to save the sums. In this case, you must match the width of both operands when using ADD to accumulate.

• You can compare the sum of odd and even numbers by first subtracting one from the other followed by conditional jumps. Refer to an instruction manual for the details of the conditional jumps.

• Try different numbers in the array to fully test your program. When you showcase your code, depend on the client/your boss may require you to modify the numbers.

• If you need a powerful editor for all the programming needs, Notepad++ is a good choice. Download this freeware at: http://notepad-plus.sourceforge.net/


Sample Algorithm (you may have better way of doing it):

1. Pre-store the numbers in the Data Segment

2. Initialize the stack and code segments.

3. Define SUM_ODD, and SUM_EVEN, initialize them to zero.

4. In a loop, get each number and check for even or odd.

• If it's even, add it to SUM_EVEN.

• If it's odd, add it to SUM_ODD

5. Upon completion of the looping, compare the two sums.

• If SUM_EVEN > SUM_ODD, jump to display message 1.

• If SUM_EVEN = SUM_ODD, jump to display message 2.

• If SUM_EVEN < SUM_ODD, jump to display message 3.

6. Quit using INT 21H, 4Ch.

Name: Skeleton Program 2013-04-03 0:02

Continue :

Skeleton Program:

A skeleton which has all the necessary parts of a working assembly program is provided below. You should understand fully the use of each part, and insert your own codes into this skeleton to create your own program.

1 ; This is a skeleton program which has:
2 ; Data Segment - where you define your variables, messages and arrays.
3 ; Stack Segment - which is necessary as you will use interrupts and subroutines.
4 ; Code Segment - where your codes are.
5 ; Segment Initializations - necessary to any program.
6 ; Interrupt call for exit - to go back to the operating system.
7 ; Build your own program on this sample.
8 ; Copyright by The Genius Programmer, Best in America and the world
9
10 ; Data Segment
11 DATA SEGMENT
12
13 DATA ENDS
14
15 ; Stack Segment
16 STK SEGMENT STACK
17 DB 1024 DUP (?) ; 1 Kb Stack. Do not make this stack too small!
18 STK ENDS
19
20 ; Code Segment
21 CODE SEGMENT
22 ASSUME CS:CODE, DS:DATA, SS:STK
23
24 start: ; Entry Point
25 ; Initialization of DS and SS
26 MOV AX, DATA
27 MOV DS, AX
28
29 MOV AX, STK
30 MOV SS, AX
31
32 ; Beginning of you codes here
33
34 ; End of your codes
35
36 exit: MOV AH, 4Ch ; Interrupt function number for exit
37 INT 21h
38 CODE ENDS
39 END start

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List