Professional Documents
Culture Documents
10:59 PM
Convert the following decimal numbers into binary and hexadecimal numbers:
108
4848
9000
Convert the following binary numbers into hexadecimal and decimal numbers:
1000011000
10000000
101010101010
Convert the following hexadecimal numbers into binary and decimal numbers:
ABCDE
CPE 005B Page 1
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
ABCDE
1234
80F
Convert the following decimal numbers into binary equivalent:
19.25D
123.456D
Answers: You could use the Windows' Calculator (calc.exe) to carry out number system
conversion, by setting it to the scientific mode. (Run "calc" Select "View" menu Choose
"Programmer" or "Scientific" mode.)
1101100B, 1001011110000B, 10001100101000B, 6CH, 12F0H, 2328H.
218H, 80H, AAAH, 536D, 128D, 2730D.
10101011110011011110B, 1001000110100B, 100000001111B, 703710D, 4660D, 2063D.
??
From <http://www.ntu.edu.sg/home/ehchua/programming/java/datarepresentation.html>
CPU Registers
Sunday, November 30, 2014
9:45 PM
Addition:
ADD destination, source
ADD destination, immediate data
ADC, which means to add the two operands plus the carry flag.
Subtraction:
SUB destination, source
SUB destination, immediate data
SBB which means to subtract minus the carry flag
*Carry Flag is set to 1 if a larger number was subtracted from a smaller number and a borrow has occurred
CPE 005B Page 3
*Carry Flag is set to 1 if a larger number was subtracted from a smaller number and a borrow has occurred
No. of Bits
Multiplicand
Multiplier
Product
8 bits x 8
AL
16 bits x 16
AX
32 bits x 32
EAX
Dividend
Divisor
16 bits / 8
AX
32 bits / 16
DX:AX
64 bits / 32
Quotient Remainder
AL
AH
DX
EDX
Audio
Recording
1. Carry - No Carry NC (0) or Carry CY (1). Kung may carry!
*sets when there is a carry on the Most Significant Digit
*Set if the result of the instruction has gone beyond the limit of the data size (ie. a "carry" has occurred).
*In addition, 255 +1 sets the carry flag, since 256 is beyond the upper limit of 255.
*1111 + 0001 = 0000 (carry flag is turned on)
*In subtraction, 02 - 04 also sets the carry flag since -2 is beyond the lower limit of 0.
*0000 - 0001 = 1111 (carry flag is turned on)
2. Sign - Sign Flag PL (0) or Sign Flag Negative NG (1). Kung negative!
*sets when the most significant digit (leftmost bit) is equal to 1.
3. Parity - Parity Odd (0) or Parity Even (1). Even ba yung number of ones!
*Only changes AFTER AN ARITHMETIC OPERATION.
*The parity flag indicates whether there are an even or odd number of bit set in the data.
CPE 005B Page 4
*The parity flag indicates whether there are an even or odd number of bit set in the data.
*Convert the result to binary to find out if it's parity even or parity odd.
Example:
1) Result: 0000 --> #1s = 0. Parity even!
2) Result: FC1F --> 1111 / 1100 / 0001 / 1111. #1s = 11. Parity odd!
4. Auxiliary Carry - No Auxiliary Carry NA (0) or Auxiliary Carry AC (1). Kung may carry sa gitna!
*For 8 bits, sets if there's a carry from 4th to 5th bit.
*For 16 bits, sets if there's a carry from 8th to 9th bit.
*For 32 bits, sets if there's a carry from 16th to 17th bit.
Example:
AX = 1111 0101
+1111 1010
0110 1111
*Turns on the carry flag, but no auxiliary carry.
AX = 1111 1111
+0000 0001
0000 0000
*Turns on the carry flag and the auxiliary carry.
5. Overflow Flag - No Overflow NV (0) or Overflow OV (1). For signed numbers only!
*Kailangang parehong 1 or 0 ang addends, tapos kabaliktaran ang result. 1 +1 = 0 or 0 + 0 =1
Rules for Overflow Flags:
1. If the sum of two numbers with the sign bits off yields a result number with the sign bit on, the "overflow" flag is turned on.
*0100 + 0100 = 1000 (overflow flag is turned on)
2. If the sum of two numbers with the sign bits on yields a result number with the sign bit off, the "overflow" flag is turned on.
*1000 + 1000 = 0000 (overflow flag is turned on)
* Note that you only need to look at the sign bits (leftmost) of the three numbers to decide if the overflow flag is turned on or off.
6. Zero: No Zero NZ(0) or Zero ZR (1). Kung equal to zero yung value!
*Tells us if the result is equal to zero.
*1000 - 1000 = 0000 (ZR)
12:47 AM
Data Representation
Monday, December 15, 2014
9:18 PM
Bit (Binary Digit) - 0, 1 (smallest unit that represents data inside the computer)
* Most significant bit - left most bit
* Least significant bit - right most bit
*Signed bit = - (1) or + (0)
*Unsigned bit = +
Bytes: 8 bits, basic storage unit for IA-32-based computer
Words: 16 bits
Double Words: 32 bits
Quad Words: 64 bits
Storage Type Unsigned Range Signed Range
Byte
0 --> 28-1
Word
0 --> 216-1
0 --> 264-1
Quad Word
Measurements
Number of Bytes
Kilobyte
210
Megabyte
220
Gigabyte
230
Terabyte
240
Petabyte
250
Exabyte
260
Zettabyte
270
Yottabyte
280
Number System
Monday, December 15, 2014
11:26 PM
Lab Activities
Monday, December 15, 2014
11:48 PM
ii. Directives - statements that provide information to tell the assembler how to generate executable
code. A statement that affects either the program listing or the way machine code is generated.
1) Count DB 50 directive tells the assembler to create a storage for a byte variable named count
and initialize it to 50.
2) .Stack 4096 directive tells the assembler to reserve 4096 bytes of stack space.
3. Names: identifies a label, variable, symbol or keyword. It may contain any of the following characters:
a.
b.
c.
d.
f. Keyword. A keyword always has some predefined meaning to the assembler. (mov, proc, title, add, ax,
END)
*.model small - a directive that indicates that uses a type of structure in which the program
uses no more than 64K of memory for code, and 64K for data.
*.stack 100h - a directive that sets aside 100h (256) bytes of stack space for the program
*.data - a directive that marks the beginning of the data segment where variables are stored.
The assembler allocates a block of memory to hold the string containing "Hello,world!" along
with two bytes containing a newline character sequence (odh, 0ah). String terminator ($).
*.code marks the beginning of the code segment where the executable instructions are
located.
*PROC directive declares the beginning of a procedure. Main is the procedure!
*mov ax, @data / mov ds, ax --> To copy the address of the data segment into DS register.
*mov ah,09 --> display a character string.
*mov ax,4C00h / int 21h) --> halt the pgoram and return control of the operating system.z
*MAIN ENDP --> to end main proc
*end main --> ending
11:15 PM
*Assembler: a utility program that converts a source program into an object file
*Linker: a program that converts object files into executable programs
Advantages of an assembler than debug:
1. Can use text editor.
2. Can use symbolic names for variables, rather than hard-coded numeric addresses.
Advantage of a Linker:
1. Programs can take advantage of existing libraries full of useful subroutines.
Listing file (optional) - produced by assembly. copy of the program's source file (suitable for printing)
with line numbers and translated machine code. To create a listing file, use the coding below.
Map file (optional) - produced by linker. Contains information about the program's code, data and stack
segments. To create a map file:
Link library - file containing subroutines that are already compiled into machine language
Warning Messages: will assemble but the object file may have errors.
DUP Operator: duplicates or repeat one or more values when allocating space.
CPE 005B Page 17
DUP Operator: duplicates or repeat one or more values when allocating space.
Pointer. The offset of a variable or subroutine can be stored in another variable, called a
pointer.
*When storing word, the first offset is given on the rightmost side.
3. Defined Doubleword (DD) - for storage of 4byte values.
12:50 AM
2. EQU directive - assigns a symbolic name to a string or numeric constant. Same as equal sign
directive, but cannot be redefined later in the program.
3. TEXTEQU directive
* reg should be any non-segment register, except that IP cannot be a target operand.
* sizes of both operands must be the same.
4. INC / DEC = +1 / -1
3. Direct Operands: refers to the contents of memory at a location identified by a label in the data
segment.
1:17 AM
Example:
*mov ax,5
cmp ax,10 --> ZF = 0, CF = 1
*mov ax,1000
mov cx,1000
cmp cx,ax --> ZF = 1, CF = 0
AND Instruction
Wednesday, January 21, 2015
1:39 AM
Jcond Instruction
Wednesday, January 21, 2015
1:49 AM
N,
M - Logical Instructions
Saturday, January 24, 2015
3:18 PM
AND / TEST
OR
XOR
2. provides an easy way to translate a letter from lower case to upper case. To convert a lower case character to an
upper case letter, use AND x, 11011111b
Example:
0110 0001 - a
0100 0001 - A
OR Instruction (OR destination, source) - Union
1. can be used to set certain bit to 1 in a byte or word
Example 1:
mov dl,03 ; 03 --> 0011
OR dl, 20h ; 20h --> 10 0000
Result: 10 0011
Example 2:
Suppose, for example, that your computer is attached to a servo motor, which is activated by setting bit 2 in its
control byte. Assuming that the AL register contains a control byte in which each bit contains some important
information, the following code only sets the bit in position 2.
OR AL,00000100b ; set bit 2, leave others unchanged
Example 3:
2.Flag statuses:
If you OR the register itself (e.g OR AL,AL), you will know the value based on the zero flag and sign flag.
2. Any register / memory XORed to itself is equal to zero. (e.g XOR al,al)
3. To initialize zero in a register, XOR AL, AL is faster in 8086 / 8088 processors than using mov al,00h.
3. To check parity, you can XOR a number with a zero. (XOR X,0)
TEST instruction
1. similar to AND instruction except that destination value does not change, but flags status are changed.
2. valuable in finding out if individual bits in an operand are set
Example:
Testing Multiple Bits The TEST instruction can check several bits at once. Suppose we want to know whether bit 0 or
bit 3 is set in the AL register. We can use the following instruction to find this out:
Test al, 0000 1000b --> tests bits zero and 3 if they are set or clear
0 0 1 0 0 1 0 1 <- input value
0 0 0 0 1 0 0 1 <- test value
0 0 0 0 0 0 0 1 <- result : ZF = 0
0 0 1 0 0 1 0 0 <- input value
0 0 0 0 1 0 0 1 <- test value
0 0 0 0 0 0 0 0 <- result: ZF = 1
NOT Instruction (NOT reg/mem) - Compliment
- reverses all bits / gets 1 compliment.
- cannot toggle imm data.
- no flags are affected!
10:04 PM
2. Arithmetic Shift - the newly created bit position is filled with a copy of the original number's sign bit. Si MSD will be repeated twice
sa unahan.
Syntax:
1. reg, imm
CPE 005B Page 32
1. reg, imm
2. mem, imm
3. reg, CL register
4. mem, CL register
*where imm is any integer between 0 and 255.
1. SHL Instruction
*The SHL (shift left) instruction performs a logical shift on the destination operand, filling the lowest bit with 0. The highest bit is
moved to the Carry flag and the bit that was initially in the Carry flag is discarded.
*MSD becomes the new Carry Flag.
*LSD becomes zero.
*If it is shifted more than once, the last MSD becomes the CF.
Example:
Bitwise Multiplication:
*SHL can perform multiplication by powers of 2. Shifting any operand left by n bits multiplies the operand by 2n.
Example 1: When we SHL 5 by one bit, 5 * 2 = 10
2. SHR Instruction:
*performs a logical right shift on the destination operand, replacing the highest bit with a 0. The lowest bit is copied into the
Carry flag, and the bit that was previously in the Carry flag is lost.
*MSD becomes zero.
*LSD becomes the Carry Flag.
*In a multiple shift operation, the last bit to be shifted out of position 0 (the LSB) ends up in the Carry flag.
Example 1:
Bitwise Division: Logically shifting an unsigned integer to the right by n bits divides the operand by 2n.
Example 2:
Signed Division: You can divide a signed operand by a power of 2, using the SAR instruction.
Example 1: When you SAR -128 by 3 bits, -128 / 23 = -16
Sign-Extend AX into EAX: Suppose AX contains a signed integer and you want to extend its sign into EAX. First shift EAX 16 bits to
the left, then shift it arithmetically 16 bits to the right.
4. ROL Instruction:
*The ROL (rotate left) instruction shifts each bit to the left. The highest bit is copied into the Carry flag and the lowest bit position.
The instruction format is the same as for SHL.
Example 1:
Example 2:
Exchanging Groups of Bits: Use ROL to exchange the upper bits (bits 4-7) and lower bits (0-3) halves of a byte.
Example 1: 26h rotated 4 times becomes 62h
Example 2: When ROL is applied by 4 bits, the characters goes to the left.
5. ROR Instruction
*ROR (rotate right) instruction shifts each bit to n right and copies the lowest bit into the Carry flag and the highest bit position.
Example 1:
Example 1:
Example 2:
RCR Instruction:
*shifts each bit to the right, copies the Carry flag into the MSB and copies the LSB into the Carry flag.
F - Screen Attributes
*Screen has 80 columns (0 - 79 ) and 25 (0-24) rows.
Int 10h / Function 06h - handles the processing of clearing the screen
* mov ah,06h = function
* al = number of blank lines at the bottom of the window
* cl = column number start
* dl = column number end
* ch = row number start
* dh = row number end
* bh = display attributes for blank lines