-----------------------------------------------------------------------
Review of the quiz we just took:
(1a, part 1) Decimal equivalent of unsigned binary 10100101 = 165
(1a, part 2) If the above is a signed number = -91
(1b, part 1) Decimal equivalent of unsigned binary 01100101=101
(1b, part 2) If the above is signed = 101
(2a) Do the following addition in binary:
01011001
+00111011
----------
10010100
(2b) Do the following subtraction in binary
01101011
-00011010
----------
01010001
(3) In this question you are to interpret hexadecimal numbers by converting them to their decimal equivalents.
(a) What is the decimal equivalent of 32 assuming the number is unsigned? 50
(b) What is the decimal equivalent of bd
assuming the number is unsigned? 189
-----------------------------------------------------------------------
Registers
AX, BX, CX and DX are called Data registers, aka "Scratch pad" registers.
In the '386 and above, there are 32-bit data registers, EAX, EBX, ECX and EDX.
AX is divided into AH and AL (2 8-bit parts)
BX is composed of BH and BL, and so on.
The segment registers
are CS, DS, SS and ES; each of which has also a 32-bit equivalent
in the 32-bit machine.
The offset registers
are SI, DI, BP, IP and SP, each of which are 16 bits. (The first
three are also known as Index registers; the last two as Special
registers.)
Since each address consists of two parts, segment and offset,
the segment part of the address is stored in a segment register
and the offset is stored in an offset register.
Each instruction in a program has an implied
register usage. For example, MOV AX, LOC, the symbolic
name, LOC, implies that the Data Segment DS is the segment address
plus some offset.
In your assembler program, LOC would be declared in the .data part:
.data
LOC DW 15
.code
A MOV AX,LOC ; A is a label. DS is implied as the segment of
; LOC.
JMP A ; execute instructions beginning from A,
; implicitly using the CS segment to find A.
MOV AX, CS:103 ; would move 16 bits from offset 103 in the
; code segment.
PUSH AX ; PUSH and POP automatically use SS as the
POP AX ; segment address, and SP (the stack pointer)
; as the offset.
Mult can only use the AX register for its operand, and the result ends up in AX and DX.
When you do division, the answer is in AX, with the remainder
in DX.
You have no direct address to the instruction pointer, IP,
which is used in conjunction with the code segment. When you do
a JMP instruction, the IP register is affected. Simply completing
an instruction, points IP to the next instruction to execute.
The other part of the register structure is the FLAG register,
which represents the status created by the last instruction that
affected these flags. NOT ALL INSTRUCTIONS AFFECT THIS REGISTER.
For example, INC and DEC do not affect this register.
The following instructions examine the flags register:
JNZ will jump if Zero flag is 0.
JP jump if positive (Sign flag)
JN jump if negative (Sign flag)
(There are about 30 jump instructions, many of which examine
this register)
Registers are much faster than working directly with memory, because memory must be accessed twice for it to work.
ADD LOC, 1 ; is a very slow event
INC LOC ; also very slow
MOV AX, LOC
ADD AX, 1
INC AX
would be much faster
DX is used as a pointer for input and output.
-----------------------------------------------------------------------
Video is memory-mapped
-- each screen position has a distinct memory address. When DOS
writes to display a character, it calls a subroutine in ROM BIOS
which writes directly to a video memory address.
For example: (try this in DEBUG)
F B800:0 500 2B,71 ; B800 is location, 500 is the # of
;characters. 2B is a plus sign,
; 71 indicates the color
F B800:100 200 2C 72 ; 2C is a comma
-----------------------------------------------------------------------
symbol: represents a value, variable, address, label or operand.
variable: symbolic name for a location in memory where data may be stored.
label: identifies a variable and shows the starting location for that variable. For example, in the statement NAME1 db "this is it", name1 points to the first character T in that string. In the statement.
offset: The distance from the beginning of the data segment to the beginning of the variable. For example:
.data
var1 db "string of stuff"
var2 db 13
var3 dw 4
var4 db 3
Each variable has a different offset. The address of the string "string of stuff" can be thought of @data. When your program statement says
MOV AX,@DATA
MOV DS,AX
MOV AL, VAR2
it knows where to find VAR2 because the data segment is in DS.
The offset of Var1 is 0. The offset of var2 would be 15, because "string of stuff" is 15 characters long.
When the assembler puts together the instruction MOV AL, VAR2,
the offset 000F will replace var2.
-----------------------------------------------------------------------
Assembler directives
db define byte
dw define word (2 bytes)
dd define doubleword (4 bytes)
df define far pointer
dp define pointer
dq define quad word (16 bytes)
dt define 10 bytes
.data
nums db 1,3,5,7,9 ; consumes 5 bytes. Think of it as an array.
sum db ? ; no initial value specified
awd dw 1278h ; 78 goes into offset awd, 12 goes into offset awd+1
.code
MOVE AX,@data
MOV DS, AX
MOV AL, nums ; puts 1 into AL.
ADD AL, nums+1 ; adds 3 to the value in AL, so it now contains
; 4.
ADD AL, nums+2 ; adds 5 to the value in AL
ADD AL, nums+3
ADD AL, nums+4
MOV sum, AL ; same as saying nums+5, AL since nums+5 and sum are
; the same thing.
MOV AX, AWD ; ax will retain 1278
MOV AL, AWD+1 ; AL will be 78.
-----------------------------------------------------------------------
Answers to homework
that was due this week
Page 40
2. Memory-intensive programs that require more than 1mb
3. Single-user architecture, original limit of 256k RAM.
6. Address must first be decoded and translated into 20-bit address, then the information must be fetched from that location and returned to the CPU before anything can be done.
22. 9FFFF
23. DOS Interrupt Vector table. Table of pointers that point to dos's internal routines for handling each of the interrupts.
24. Keyboard status flag, typeahead buffer.
25. No. Monochrome buffer is at B000, color buffer is at B800.
26. BIOS.
27. SS
28. SP
29. POP
30. Downward
31. Because only the value most recently placed on the stack is pointed to by SP. Last In, First Out.
32. absolute
33. No. It can be loaded into any large enough segment available.
[back to the main csc220 page] [To the downloadable files] [To Maggie's homepage]