storage & simple movement
.. Registers: storing data in the CPU and a little about Cache Memory
mem Where do we store values? How much storage? What type of binary coding?
What are REGISTERS? Advantages in using? Are they necessary? * emu8086 does NOT use 32 bit registers (eax, ebx, etc...)

Examples: moving data into registers MOV al, 255 MOV ax, 0f54ah MOV bx, -1 MOV bh, 11010101b
Are these different from each other? MOV ah, -1 MOV ah, 0ffh MOV ah, 11111111b MOV ah, 255
ugh... MOV ax, 1110001101011101b MOV ax, ?? in hex ??

Sign: result is negative Zero: result is zero Carry: unsigned arithmetic out of range Overflow: signed arithmetic out of range

Problem?? MOV al, 0ffh ADD al, 1

problem? when? how do we know???

Can't we just store everything in registers? Why not?

Cache Memory

because CPU speeds got faster faster than RAM speeds got faster (!) faster hardware plus "pre-fetch" based on best guess based on "locality of reference" spaghetti code may break cache advantages cache cache cache

.. Data Definitions: storing data in RAM
Better than registers? ====================== Where do we store values? How much storage do we use? What type of binary coding? How do we define storage?
RAM Data definition statement sets aside storage in memory. May optionally assign a name (label) to the data Syntax: [name] directive initializer [,initializer] . . . price DW 0 fname DB "Joseph",0

DB 8-bit unsigned & signed integer DW 16-bit unsigned & signed integer DD 32-bit unsigned & signed integer
first DB 10, 32, 41h second DB 0Ah, 20h, 'A' third DB ? --------------------------------------------- How many bytes? How organized? How represented? Draw it! Symbol Table?
value1 DB 'A' ; character constant value2 DB 0 ; smallest unsigned byte value3 DB 255 ; largest unsigned byte value4 DB -128 ; smallest signed byte value5 DB +127 ; largest signed byte value6 DB ? ; uninitialized byte
list1 DB 10, 32, 41h, 00100010b list2 DB 0Ah, 20h, 'A', 22h array1 DB 20 DUP(0) greeting1 DB "Good afternoon", 0 A string is stored as a sequence of bytes - why ZERO at end?

Labels let you use symbolic names for memory locations!

The offset of a byte in storage is the distance from the beginning of the segment (.data) to the first byte of the variable.
Remember this one? first db 10, 32, 41h second db 0Ah, 20h, 'A' third db ? --------------------------------------------- How represented? Draw it! Symbol Table? Memory Symbol Table**** 0 - 0A first = 0 1 - 20 second = 3 2 - 41 third = 6 3 - 0A 4 - 20 5 - 41 6 - ??
; how do you access the 'D'? Var1 db 'ABC' Var2 db "DEFG" The offset of Var1 ('A') is 0 'B' is at offset Var1 + 1 = 1 'D' is at offset Var2 or at Var1+3 = 3 'F' is at offset Var2+2 or at Var1+5 = 5
; how do you access the '4'? Var1 db 3, 7 Var2 db 4, 25 The offset of Var1 (3) is 0 7 is at offset Var1 + 1 = 1 4 is at offset Var2 or at Var1+2 = 2 25 is at offset Var2+1 or at Var1+3 = 3
String Examples: str1 DB "Enter your name",0 str2 DB 'Error: halting program',0 str3 DB 'A','E','I','O','U' greeting1 BYTE "Welcome to assembly " BYTE "language", 0Dh,0Ah, 0 0Dh is what? 0Ah is what?
DUP does what? var1 DB 20 DUP(0) ; 20 bytes, all equal to zero var2 DB 20 DUP(?) ; 20 bytes, uninitialized var3 DB 10, 13, 65, 3 DUP(0), 20 ;
; ----------------- Word Values --------------------- ======================================================= word1 DW 65535 ; largest unsigned value word1 DW 0 ; smallest unsigned value word2 DW 32767 ; largest signed value word2 DW -32768 ; smallest signed value word3 DW ? ; uninitialized
What is "little Endian? Intel's x86 are little endian processors: the lowest order byte (of a word or double word) is stored at the lowest address. X DW 1234h ; 2 bytes at X ------------------------- offset: value: 0 34h - least significant byte 1 12h - most X DW 256 ; 2 bytes at X ------------------------- offset: value: 0 00h - least significant byte 1 01h - most X DW 256, 1234h ; 4 bytes at X ------------------------- offset: value: 0 00h - least significant byte 1 01h - most 2 34h - least significant byte 3 12h - most
If a value fits into a byte, it will be stored in the lowest ordered one available. Ex: init DW 'A' ;ascii code 41h the value will be stored as: ------------------------- offset: value: 0 41h - least significant byte 1 00h - most init DW 'AB' ; ascii codes 41h, 42h ------------------------- offset: value: 0 41h - least significant byte 1 42h - most

.. Constants data: =, EQU and $
= Symbolic Constant name = expression expression is a 32-bit integer MAY be redefined prod = 10 * 5 ; Evaluates an expression maxInt = 7FFFh ; Maximum 16-bit signed value minInt = 8000h ; Minimum 16-bit signed value maxUInt = 0FFFFh ; Maximum 16-bit unsigned value string = 'XY' ; Up to two characters allowed count = 500 WHY? good programming?? NO STORAGE ALLOCATED!! ^^
EQU Define a symbol as either an integer OR text expression. May NOT be redefined PI EQU 3.1416 pressKey EQU "Press any key to continue..." ;NO STORAGE ALLOCATED!! ^^ prompt DB pressKey ; storage IS allocated here... ^^

.. The location counter: $
$ Location counter used at assembly time tracks the offset from 0 (start) of where each byte of the program is stored as it is generated Program counter used at run time tracks the instruction address of the next executable instruction
$ operator returns the current value of LOCATION COUNTER. Use it to compute the string length at assembly time. list DB 10,20,30,40 ListSize = ($ - list) so the value of List Size is ?? ----------------------------------- list DB 10,20,30,40, 50, 60, 70 ListSize = ($ - list) so the value of List Size is ?? ----------------------------------- LongString db 'This is a piece of text that I' db 'want to type on 2 separate lines' LongString_length = ($ - LongString) Offset of w (in want) = 1 + offset of I Note: do not need to put a label on every line... in fact everything could be an offset from a label at ZERO - why bad?

.. Little Endian Order
Little Endian Order =================== Little endian order refers to the way Intel stores integers in memory. Multi-byte integers are stored in reverse order, with least significant byte stored at lowest address For example, the doubleword 12345678h would be stored as: DD 12345678h PTR can also be used to combine elements of a smaller data type and move them into a larger operand. myBytes DB 12h,34h,56h,78h mov ax, WORD PTR [myBytes] ;AX = 3412h mov ax, WORD PTR [myBytes+1] ;AX = 5634h mov ax, WORD PTR [myBytes+2] ;AX = 7856h mov eax, DWORD PTR myBytes ;EAX = 78563412h
varB DB 65h, 31h, 02h, 05h varW DW 6543h, 1202h varD DD 12345678h mov ax, WORD PTR [varB+2] ; a. 0502h mov bl, BYTE PTR varD ; b. 78h mov bl, BYTE PTR [varW+2] ; c. 02h mov ax, WORD PTR [varD+2] ; d. 1234h mov eax, DWORD PTR varW ; e. 12026543h

.. emu 8086: registers & memory (RAM)
why 20 bit addresses? why not just use the 16 in the register? how do you construct a 20 bit address? segment: offset 1234:7890 => 1234h * 10h + 7890h = 12340 + 7890 ----- 19BD0h
emulator: 16 bit registers and memory with 20 bit addresses
memory map