Top Banner
PC Assembler Ing. E.E. Mak MSc
18

PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Dec 31, 2015

Download

Documents

Moris Wood
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

PC Assembler

Ing. E.E. Mak MSc

Page 2: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Cluster1

• Introduction

• Microprocessors

• Numbers, Binary, Hexadecimal, ASCII

• Adding and subtracting

• Instructions and Flags

• Deeds Z80 simulator

Page 3: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Computer Lay-out

MEMdata+instructions

CPU

I/O External

Page 4: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Model CPU

PC R2R1

IR

M

A

RM

D

R

ALU

A B

SR DECODER

ICU TIMER

C

CLOCK

Page 5: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Z80 Processor Register Layout

Main registers. Alternative registers.

S

Z

-

H

-

P/V

N

C

Sign

Zero

-

Half-Carry

-

Parity/overfl.

Negate

Carry

Flags 8 bit

Adress Registers

Accumulator Registers

Interupt

register

Memory

Refresh

Alternative Registers

W’B’

H’D’

Z’C’

L’E’

WB

HD

A F’FA’

ZC

LE

I

R

I XI Y

S PP C

Page 6: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Negative Numbers

0 1 11 0 1 0053 =

1 1 11 0 1 00-53 =

Using the 8-th bit as a SIGN bit

0 1 11 0 1 0053 =

1 0 00 1 0 11-53 =

Inverting the bits

Page 7: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Two’s Complement

0 0 10 1 1 00

1 1 01 0 0 11

13

1

1 1 01 0 0 11

inv

+1

Two’s Complement

Page 8: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Packed Decimals

0 1 11 0 1 00

3 535 =

0 1 11 0 1 0053 = binary

Binary packed decimal

Page 9: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Addition

1 1 10 0 0 00

0 0 10 0 1 01

1 1 00 0 1 11

+

Page 10: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Subtraction

1 1 10 0 0 00

0 0 10 0 1 01

1 1 00 0 1 11

-

Page 11: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Flags

• Carry

• Overflow

• Zero

• Negative

• ..

• …

• ...

Page 12: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Generic Instructions

• Input/output data• Load a value(register) into a register• Arithmetic• jumping / subroutine• control• Bitwise operators : Boolean, Register shifts • interrupt handling• stacking

Page 13: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Example programs

LD A,86d

ADD A,57d

LD A,86d

ADC A,57d

Page 14: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Example programs2

Adding 57 to HL:

LD A,LADD A,57dLD L,ALD A,HADC A,0LD H,A

Page 15: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Assignments1. Write a program to store 100 into DE and 385 into BC ADD thereafter DE and BC into HL

2. Investigate substraction using negative numbers forall number-configurations demonstrated in previoussheets

3. Investigate how to multiply using binary numbers

4. Investigate using shift operators could facilitatethe multiplication process.

5. What are floating point decimals , how are they implemented?

Page 16: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

links

• Simple reference list Z80 opcodes:– http://www.ticalc.org/pub/text/z80/z80.txt

• Lots of information about the Z80– http://www.z80.info/

• full reference list op-codes Z80:– http://www.ticalc.org/pub/text/z80/z80_reference.txt

• Crash-course Z80 assembly-programming– http://www.ticalc.org/pub/text/z80/z80asmg.zip

Page 17: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Binary Packed

The use of half bytes let us express two adjacent hexadecimal numbers. As a consequence, we may use this two-digit hexadecimal byte presentation to perform calculations as well, whereas the carry-mechanism while adding work accordingly

0E

0 1 00 1 0 00

0 0 01 1 0 10

0 0 00 1 1 10

+1A

28

In hexadecimal coding, each digit of one halfbyte represents a hexadecimal number

Page 18: PC Assembler Ing. E.E. Mak MSc. Cluster1 Introduction Microprocessors Numbers, Binary, Hexadecimal, ASCII Adding and subtracting Instructions and Flags.

Binary Packed Decimal

The use of half bytes for numbers 0..9 only, forces while adding special corrections to facilitate adding of these decimal numbers.

(What would the result have been without this corrections?)

07

0 1 00 0 1 00

0 0 11 0 1 10

0 0 10 0 1 10

+17

24

Could you develop an algorithm to make this corrections?