# RodnayQuest

*Rodnay, my guide*

*Whisper in the night*

## Contents

## Chapter 1 - Basic Concepts

- 8 bits = 1 byte
- 4 bits = 1 nibble

Binary format is used here for three internal representation of information: program, numbers, alphanumerics.

### Program

Instructions are represented by either one byte (short instruction) or multiple bytes. Multi-bytes instructions takes more time than single-byte short instructions, because the 6502 is a 8-bit microprocessor, so it fetches bytes successively from its memory.

### Numbers

Three are three representations of numeric data: integer, signed, decimal.

#### Two's Complement Representation

In the two's complement representation, positive numbers are still represented, in signed binary, just like in one's complement. The difference lies in the representation of negative numbers. A negative number represented in two's complement is obtained by first computing the one's complement, and then adding one.

#### BCD Representation

The principle used in representing numbers in BCD is to encode each decimal digit separately, and to use as many bits as necessary to represent the complete,number exactly.

#### Integer

Direct binary representation:

b7b6b5b4b3b2b1b0 = b7*2^7 + b6*2^6 + b5*2^5 + b4*2^4 + b3*2^3 + b2*2^2 + b1*2^1 + b0*2^0 128 64 32 16 8 4 2 1

E1.1

11111100 = 128 + 64 + 32 + 16 + 8 + 4 + 0 + 0 = 252

257 cannot be represented with 8 bits, with 9 bits it would be 1 0000 0001

E1.3

19/2 = 9 remains 1 <- LSB 9/2 = 4 remains 1 4/2 = 2 remains 0 2/2 = 1 remains 0 1/2 = 0 remains 1 <- MSB

19 -> 00010011 -> 16 + 2 + 1 = 19

Addition:

0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 + carry of 1

E1.4

5 00000101 + 10 00001010 ------------ 15 00001111 00001111 -> 8 + 4 + 2 + 1 = 15

15/2 = 7 remains 1 7/2 = 3 remains 1 3/2 = 1 remains 1 1/2 = 0 remains 1

E1.5

1111 + 0001 ---- 0000 + Carry of 1

The result does not fit in 4 bits!

#### Signed

S b b b b b b b | `-----------' | | | `-> NUMBER MAGNITUDE (7 bits) | `-> SIGN: 0 positive 1 negative

E1.6

5 = 00000101 -5 = 10000101

One's complement, used as intermediary step to allow correct signed additions.

5 = 00000101 DIRECT BINARY REPRESENTATION or SIGNED BINARY (POS) -5 = 10000101 SIGNED BINARY (NEG) -5 = 11111010 ONE'S COMPLEMENT

E1.7

6 = 00000110 DIRECT BINARY REPRESENTATION -6 = 11111001 ONE'S COMPLEMENT

Two's complement:

- for positive number = signed binary representation
- for negative number = one's complement + 1

All signed integers in the 6502 are internally represented as two's complement.

Example:

5 = 00000101 TWO'S COMPLEMENT (same as POSITIVE SIGNED BINARY) -5 = 11111011 TWO'S COMPLEMENT (11111010 + 1)

E1.8

+127 -> 01111111

E1.9, E1.10, E.1.11

-128 -> 10000000

The magnitude of an signed integer is 7 bits, so the smaller number that can be represented is 0 and the larger 127.

20 -> 00010100 11101011 11101100 00010011 00010100 -> 20!

## Chapter 2: The Quest Continues

E1.12, E1.13, E1.14

10111111 + 11000001 __________ = 10000000 V:NO C:Yes CORRECT

11111010 + 11111001 __________ = 11110011 V:No C:Yes CORRECT

00010000 + 01000000 __________ = 01010000 V:No C:No CORRECT Nothing happening here

01111110 + 00101010 __________ = 10101000 V: Yes C:No ERROR help overflow fix plz

E1.13 I am trying to understand why carry and overflow cancel each other out when adding a negative number and a positive number. But I can't find a decent calculation that shows this.

E1.14

Two bytes, largest and smallest number. largest:32767 smallest:-32768

E1.15

Largest negative integer in two's complement triple precision format.

-8388608

E1.16

BCD representation = Binary Coded Decimal. Using binary to represent numbers 0 to 9 in 4 bits and not to worry about the amount of bits used for a number. (using 4 bits per decimal)

29 = 0010 1001 (2) (9) 91 = 1001 0001 (9) (1)

E1.17

1010 0000 is not a valid BCD because 1010 is unused in BCD

E1.18

-23123 in multibyte BCD is

5 - 2 3 1 2 3 0000 0101 0001 0010 0011 0001 0010 0011

The first 5 states that there will be 5 nibbles of BCD for the numbers. In this convention: the - sign doens't count, why not 6 nibbles? Why is the 5 in a byte and not in a nibble?

# Log

### DJ Crunk

**08/05/17**- Chapter 1 - E1.4**??/??/17**- Chapter 1 - E1.11

### ultrageranium

**11/05/17**- Chapter 1 - E1.11