Assembly HOMEWORK

download Assembly HOMEWORK

of 5

Transcript of Assembly HOMEWORK

  • 8/4/2019 Assembly HOMEWORK

    1/5

    = INTRO=

    Maybe sounds weird but the computer can only do two logical operations

    accumilating (+) and producting (x). These are enough for the computer to do

    any kind of task, from processing to printing and executing any sort of programm.

    This also might sound weird but the computer doesn't work in decimal arithmeticsystem but in binary, (0,1). To be more specific :

    0 : it doesn't pass any electric stream in the circuits and cells of the computer.

    1 : it pass continiously electric stream in the circuits and cells of the computer.

    So now it's obvious that all these stuff of software and programms it is made

    by us and for us so that we can communicate with the computer without typing

    countless zeros and ones in order to write or execute a programm, because despight

    the language of programming we use every computer only the binary machine code

    understands!!!

    1.) WHY ASSEMBLY ???

    First of all you need to know that assembly is the ancient language of programming

    and still in use !!! Assembly is little more higher than the machine language.

    It represents symbolically the basic processes that are done in CPU (central proccesing unit)

    From many programmers it is considered as the lowest level language. May be the

    higher level languages ( such as Pascal, Python, algol) are nearer to our natural language

    but none of them has the efficiency and immediateness of assembly. That's why it is still in

    use today for C- programming,crucial debugging processes etc.

    IF YOU DO ANY PROGRAMMING YOU WILL FIND ASSEMBLY MOST NECCESARY !!

    2.) THE ARCHITECTURE OF THE COMPUTER

    -page 1 of 4-

  • 8/4/2019 Assembly HOMEWORK

    2/5

    In the diagramm above we can see the basical structure of a computer .

    The CPU is divided in three major parts more specifically :

    The hard disc memory C : where all the necesssary programms are stored for the start

    of the computer till the display of the results in the computer screen.

    The cheking unit : where all the procedures which are executed in CPU are checked

    in order that the user won't be forced to do any debugging.ALU : in this unit all the logical operations and most of the programms and other

    kind of procedures which are done in the computer -- are executed.

    Only if all these units work together the computer can function.

    3.) ASSEMBLY LANGUAGE ON CPU 8086

    Every CPU has a serie of registers. These are like RAM when we turn off the computer

    all the stored data in there is lost. The major difference is that RAM has much more space than

    the registers.

    Because CPU's are countless we will focus only on one CPU 8086.All the registers in

    8086 have length 16 bits.

    GENERAL PURPOSE REGISTERS

    AX Accumulator register. It is seperated in AH and AL.

    BX Base adress register. It is seperated in BH and BL.

    CX Count register It is seperated in CH and CL.

    DX Data register. It is seperated in DH and DL.

    BP Base pointer

    SP Stack pointer

    SI Source index registerDI Destination index register

    The above registers store temporarily values on the binary code system.

    The first 4 registers are divided in two parts with equal amount of numbers the high

    nibble ( _H) and the low nibble ( _ L).For example CX= 1010111000101000 so

    CH= 10101110 and CL=00101000

    SEGMENT REGISTERS

    CS Code segment

    DS Data segment

    ES Extra segment

    SS Stack segment

    The above registers are used for refering in blocks of the memory C.

    The memory C is divided in segments.

    -page 2 of 4 -

  • 8/4/2019 Assembly HOMEWORK

    3/5

    SPECIAL PURPOSE REGISTERS

    IP instruction pointer

    flags register

    IP combined with CS gives the running directiveFlags register shows or determines the running state of the computer.

    These registers are controlled automatically by CPU.

    CPU 8086 INSTRUCTION SET

    Data Transfer Instructions

    MOV Move byte or word to register or memoryIN, OUT Input byte or word from port, output word to portLEA Load effective address

    LDS, LES Load pointer using data segment, extra segmentPUSH, POP Push word onto stack, pop word off stackXCHG Exchange byte or wordXLAT Translate byte using look-up table

    Logical Instructions

    NOT Logical NOT of byte or word (one's complement)AND Logical AND of byte or wordOR Logical OR of byte or wordXOR Logical exclusive-OR of byte or wordTEST Test byte or word (AND without storing)

    Shift and Rotate Instructions

    SHL, SHR Logical shift left, right byte or word? by 1 or CLSAL, SAR Arithmetic shift left, right byte or word? by 1 or CLROL, ROR Rotate left, right byte or word? by 1 or CLRCL, RCR Rotate left, right through carry byte or word? by 1 or CL

    Arithmetic Instructions

    ADD, SUB Add, subtract byte or wordADC, SBB Add, subtract byte or word and carry (borrow)

    INC, DEC Increment, decrement byte or wordNEGNegate byte or word (two's complement)CMP Compare byte or word (subtract without storing)MUL, DIV Multiply, divide byte or word (unsigned)IMUL, IDIV Integer multiply, divide byte or word (signed)CBW, CWD Convert byte to word, word to double word (useful before multiply/divide)

    Adjustments after arithmetic operations:

    AAA, AAS, AAM,AADASCII adjust for addition, subtraction, multiplication, division (ASCII

    codes 30-39)

    DAA, DAS Decimal adjust for addition, subtraction (binary coded decimal numbers)

    - page 3 of 4-

  • 8/4/2019 Assembly HOMEWORK

    4/5

    Transfer Instructions

    JMP Unconditional jump (short?127/8, near?32K,farbetween segments)Conditional jumps:

    JA (JNBE) Jump if above (not below or equal)? +127, -128 range only

    JAE (JNB) Jump if above or equal(not below)? +127, -128 range onlyJB (JNAE) Jump if below (not above or equal)? +127, -128 range onlyJBE (JNA) Jump if below or equal (not above)? +127, -128 range onlyJE (JZ) Jump if equal (zero)? +127, -128 range onlyJG (JNLE) Jump if greater (not less or equal)? +127, -128 range onlyJGE (JNL) Jump if greater or equal (not less)? +127, -128 range onlyJL (JNGE) Jump if less (not greater nor equal)? +127, -128 range onlyJLE (JNG) Jump if less or equal (not greater)? +127, -128 range onlyJC, JNC Jump if carry set, carry not set? +127, -128 range onlyJO, JNO Jump if overflow, no overflow? +127, -128 range onlyJS, JNS Jump if sign, no sign? +127, -128 range only

    JNP (JPO) Jump if no parity (parity odd)? +127, -128 range onlyJP (JPE) Jump if parity (parity even)? +127, -128 range only

    Loop control:

    LOOP Loop unconditional, count in CX, short jump to target addressLOOPE (LOOPZ) Loop if equal (zero), count in CX, short jump to target addressLOOPNE (LOOPNZ) Loop if not equal (not zero), count in CX, short jump to target addressJCXZ Jump if CX equals zero (used to skip code in loop)

    Subroutine and Interrupt Instructions

    CALL, RET Call, return from procedure (inside or outside current segment)INT, INTO Software interrupt, interrupt if overflowIRET Return from interrupt

    String Instructions

    MOVS Move byte or word stringMOVSB, MOVSW Move byte, word stringCMPS Compare byte or word stringSCAS Scan byte or word string (comparing to A or AX)LODS, STOS Load, store byte or word string to AL or AX

    Repeat instructions (placed in front of other string operations):

    REP Repeat

    REPE, REPZ Repeat while equal, zeroREPNE, REPNZ Repeat while not equal (zero)

    Processor Control Instructions

    Flag manipulation:

    STC, CLC, CMC Set, clear, complement carry flagSTD, CLD Set, clear direction flagSTI, CLI Set, clear interrupt enable flagLAHF, SAHF Load AH from flags, store AH into flagsPUSHF, POPF Push flags onto stack, pop flags off stackCoprocessor, multiprocessor interface:

    ESC Escape to external processor interfaceLOCK Lock bus during next instruction -page 4 of 5 -

  • 8/4/2019 Assembly HOMEWORK

    5/5

    Inactive states:

    NOPNo operationWAIT Wait for TEST pin activityHLT Halt processor

    LINKS

    1.) http://en.wikipedia.org/wiki/Assembly_language

    2.) en. wikipedia.org/.../Intel_8086

    3.) www.emu8086.com

    4.) courses.ece.ilinois.edu?nasm_dierctive.html

    5.) w3.usfm.br/rmbranco/cefet_files/.../8086%20

    6.) www.es.uregina.ca/.../7_Assembly.html

    7.) www.cpu-world.com/.../8086.html

    8.) www.assembly.mag.com

    9.) assembly.state.ny.us/-

    10.)www.it.uom.gr/.../assembly/contents.htm

    - page 5 of 5-

    http://www.it.uom.gr/.../assembly/contents.htmhttp://www.it.uom.gr/.../assembly/contents.htm