Chapter 2 HCS12 Assembly Language, Study notes of Logic

Commands to the assembler ... Tells the assembler to store a string of characters (a message) in ... It can be used only for BCD add but not subtraction.

Typology: Study notes

2022/2023

Uploaded on 03/01/2023

ekani
ekani 🇺🇸

4.7

(26)

265 documents

1 / 97

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dr. Mohamed Mahmoud
http://iweb.tntech.edu/mmahmoud/
Chapter 2
HCS12 Assembly Language
ECE 3120
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61

Partial preview of the text

Download Chapter 2 HCS12 Assembly Language and more Study notes Logic in PDF only on Docsity!

Dr. Mohamed Mahmoud http://iweb.tntech.edu/mmahmoud/

[email protected]

Chapter 2

HCS12 Assembly Language

ECE 3120

Outline

2.

Assembly language program structure

Arithmetic instructions

Branch and loop instructions

Shift and rotate instructions

Boolean logic instructions

2.6 Bit test and manipulate instructions

1. end- Ends a program to be processed by an assembler- Any statement following the end directive is ignored2. Org (origin)- Tells the assembler where to place the next instruction/data in

memory- Example:

org

ldab

#$FF

;this instruction will be stored in

memory starting from location $1000.

3. dc.b (define constant byte), db (define byte), fcb (form

constant byte)- Define the value of a byte or bytes that will be placed at a givenlocation.- Example:

org

array dc.b

4. dc.w (define constant word), dw (define word), fdb (form

double bytes)- Define the value of a word or words that will be placed at agiven location.- For example:

org

array

dc.w

$AC11,$F122,$33,$F

$11 $22 $33$0F$

(^800801802803)

$AC^ $F1 $

(^804805806807)

5. fcc (form constant character)

  • Tells the assembler to store a string of characters (a message) in

memory.

  • The first character (and the last character) is used as the

delimiter.

  • The last character must be the same as the first character.- The delimiter must not appear in the string.- The space character cannot be used as the delimiter.- Each character is represented by its ASCII code.

8. ds.w (define storage word), rmw (reserve memory word)

  • Reserve a number of words Dbuf ds.w 20 ;Reserves 20 words (or 40 bytes) starting

from the current location counter.

9. equ (equate)

-^

Assigns a value to a label.

-^

Makes programs more readable.

-^

Examples:

loop_count

equ 50

Informs the assembler whenever the symbol loop_count isencountered, it should be replaced with the value 50

Example 3: Two dimensional arrays

This computation isdone by assembler

Later, we will write a code to read oneand two dimensional arrays

A line of an assembly program

Label field- Labels are symbols defined by the user to identify memory

locations in the programs and data areas- Optional- Must starts with a letter (A-Z or a-z) and can be followed byletters, digits, or special symbols (_ or .)

  • Optional- Explain the function of a single or a group of instructions- For programmer – not for assembler or processor.- Ignored by assembler and are not converted to machine code.-^

Can improve a program readability -

very important in assembly

-^

Any line starts with an

or

;^

is a comment

-^

Separated from the operand and operation field for at least one space Comment field

Instructions - Instruct the processor to do a sequence of operations- Converted to machine code- Operands follow the opcode and is separated from the opcode by atleast one space- Operands are separated by commas- Opcode is the operation and separated from the label by at leastone space- Assembler instructions or directives are not case sensitive- Must not start at column 1

Instructions

Outline

Assembly language program structure

2.

Arithmetic instructions

Branch and loop instructions

Shift and rotate instructions

Boolean logic instructions

2.6 Bit test and manipulate instructions

  • Zero flag (Z): set when the result is zero- Negative flag (N): set whenever the result is negative, i.e., most

significant bit of the result is 1.

  • Half carry flag (H): set when there is a carry from the lower four

bits to the upper four bits.

  • Carry/borrow flag (C): set when addition/subtraction generates a

carry/borrow.

  • Overflow flag (V): Set when the addition of two positive numbers

results in a negative number or the addition of twonegative numbers results in a positive number. i.e.whenever the carry from the most significant bitand the second most significant bit differs

+^

C = 0,

V = 0,

Z = 0,

N = 1

Overflow

Overflow Detection 1- Unsigned numbers: Overflow occurs when C = 1, C flag can be

considered as a bit of the result.

Problem 2- Signed numbers: Overflow occurs when V = 1Overflow cannot occur when adding numbers of opposite sign why?

: fixed width registers have limited range

Overflow occurs when two numbers are added or subtracted andthe

correct

result

is

a

number

outside

the

range

that

can

a

register hold

If there is an overflow, then the given result is not correct

+ 0000 00010000 0000C =1, V =

Signed numbers:

-1 +1 = 0 , no overflow and the result is

correct

Unsigned numbers:

255 +1 = 256, overflow,

256 needs

9 bits instead of 8,

the result is

incorrect

2 - 16

Addition

C = 1, the result needs more space than the register widthV = 1, (+ve) + (+ve) = (-ve) or (–ve) + (-ve) = (+ve) Subtraction

: A - B

There is no unsigned overflow but there is signed overflowC = 1, when there is a borrow or B > AV =1, when(-ve) - (+ve) = (+ve) this is equivalent to (–ve) + (-ve) = (+ve)(+ve) - (-ve) = (-ve)

this is equivalent to (+ve) + (+ve) = (-ve)

+^

+^

Unsigned^1128

+^

Signed^1 -

C = 0V = 1

-^

-^

Unsigned

-^

Signed- 37- 109

C = 1 (called borrow),V = 1