meljun cortes manual computer organization assembly lang csci06

Upload: meljun-cortes-mbampa

Post on 04-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    1/59

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    2/59

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    3/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    /emory modelsSimpli!ied !rame in /AS/ modeSimpli!ied !rame in I.AL mode'ample program

    ( Instruction Sets.ata rans!er Instruction4ranch InstructionConditional Bumps3nconditional BumpsLooping Instructions

    Arithmetic Instructions/anipulating Instructions

    'UIZ -

    *0(Addressing /odes

    **(Procedures and /acros

    *-(/ore application programsScreen handlingeyboard handling7ile8dis handlingSerial port communication applicationPrinter port application/emory management application languageerminate stay resident programmingProgram !rame

    Assembly or high languageInter!acingIn)line assembly

    'UIZ

    7I$AL 1A/I$AIO$

    COLLEGE OF COMPUTER STUDIES PA 2

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    4/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    NUMBER SSTEM

    A #u/$er s0ste/ is 1e2i#e1 $0 t3e $4se it uses, t3e $4se $ei#5 t3e #u/$er o21i22ere#t s0/$ols, or #u/er4ls, re6uire1 $0 t3e s0ste/ to re"rese#t 4#0 o2 t3e i#2i#iteseries o2 #u/$ers.

    CON7ERSION:

    De!i/4l He841e!i/4l Bi#4r0 O!t4l

    0 0 0000 0* * 000* *- - 00*0 -2 2 00** 2< < 0*00 le!tmost? sign bit!ollo"ing a signed arithmetic operation(

    I#terru"ts 7e!tor

    Interrupts can be seen as a number o! !unctions( hese !unctions mae the programmingmuch easier, instead o! "riting a code to print a character you can simply call the interrupt and it"ill do e%erything !or you( here are also interrupt !unctions that "or "ith dis dri%e and otherhard"are( +e call such !unctions so2t;4re i#terru"ts(

    Interrupts are also triggered by di!!erent hard"are, these are called 34r1;4re i#terru"ts(Currently "e are interested in so2t;4re i#terru"tsonly(

    o mae a so2t;4re i#terru"tthere is an INTinstruction, it has %ery simple synta':INT &4lue+here &4luecan be a number bet"een 0 to -== >or 0 to 077h?, generally "e "ill usehe'adecimal numbers( ;ou may thin that there are only -=6 !unctions, but that is not correct(ach interrupt may ha%e sub)!unctions(

    o speci!y a sub)!unction AHregister should be set be!ore calling interrupt( achinterrupt may ha%e up to -=6 sub)!unctions >so "e get -=6 N -=6 G 6==26 !unctions?( In generalAH register is used, but sometimes other registers maybe in use( enerally other registers areused to pass parameters and data to sub)!unction(

    CATEGORIES O INTERRUPTS

    (. H4r1;4re I#terru"ts) mbedded in the hard"are

    ). So2t;4re I#terru"ts

    ) Are programs to e'ecute 5+ interrupt

    BIOS 4#1 DOS I#terru"t

    I$ *0h 8 A5 G 0 ) set %ideo mode(input:

    AL G desired %ideo mode(

    COLLEGE OF COMPUTER STUDIES PA **

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    12/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    these %ideo modes are supported:

    00h ) te't mode(

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    13/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    .5, .L G ro", column o! "indo"s lo"er right corner())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))I$ *0h 8 A5 G 0Ch ) change color !or a single pi'el(

    input:AL G pi'el colorC1 G column(

    .1 G ro"(

    e'ample:

    mo% al, *2hmo% ah, 0int *0h & set graphics %ideo mode(mo% al, **00bmo% c', *0mo% d', -0mo% ah, 0chint *0h & set pi'el(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))I$ *0h 8 A5 G 0.h ) get color o! a single pi'el(

    input:C1 G column(.1 G ro"(output:

    AL G pi'el color

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))I$ *0h 8 A5 G 0h ) teletype output(

    input:

    COLLEGE OF COMPUTER STUDIES PA *2

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    14/59

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    15/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    CHARACTER ATTRIBUTE

    bit color table:character attribute is bit %alue, lo" < bits set !ore color, high < bits set bacground color(note: the emulator and "indo"s command line prompt do not support bacground blining,

    ho"e%er to mae colors loo the same in dos and in !ull screen mode it is reuired to turn o!! thebacground blining(

    51 4I$ COLO9

    0 0000 blac* 000* blue- 00*0 green2 00** cyan< 0*00 red

    = 0*0* magenta6 0**0 bro"n@ 0*** light gray *000 dar gray *00* light blue

    A *0*0 light green4 *0** light cyanC **00 light red. **0* light magenta ***0 yello"7 **** "hite

    note:

    & use this code !or compatibility "ith dos8cmd prompt !ull screen mode:mo% a', *002hmo% b', 0 & disable blining(int *0h))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ **h ) get 4IOS euipment list(

    return:A1 G 4IOS euipment list "ord, actually this call returns the contents o! the "ord at00

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    16/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    4it !ields !or 4IOS)detected installed hard"are:bit>s? .escription*=)*< $umber o! parallel de%ices(*2 9eser%ed(*- ame port installed(

    **) $umber o! serial de%ices( 9eser%ed(

    @)6 $umber o! !loppy dis dri%es >minus *?: 00 single !loppy dis& 0* t"o !loppy diss& *0 three !loppy diss& ** !our !loppy diss(=)< Initial %ideo mode: 00 A,#A,PA, or other "ith on)board %ideo 4IOS&

    0* emulator de!ault?( ** 0'-= mono te't(2 9eser%ed(- PS8- mouse is installed(* /ath coprocessor installed(0 Set "hen booted !rom !loppy(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ *-h ) get memory size(

    return:A1 G ilobytes o! contiguous memory starting at absolute address 00000h, this call returns thecontents o! the "ord at 00must be nonzero?C5 G cylinder number >0((@?(CL G sector number >*((*?(.5 G head number >0((*?(

    COLLEGE OF COMPUTER STUDIES PA *6

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    17/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    .L G dri%e number >0((2 , !or the emulator it depends on uantity o! 7LOPP; !iles?(S:41 points to data bu!!er(

    return:

    C7 set on error(C7 clear i! success!ul(A5 G status >0 ) i! success!ul?(AL G number o! sectors trans!erred(

    $ote: each sector has =*- bytes(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ *=h 8 A5 G 6h ) 4IOS "ait !unction(input:

    C1:.1 G inter%al in microsecondsreturn:

    C7 clear i! success!ul >"ait inter%al elapsed?,C7 set on error or "hen "ait !unction is already in progress(

    $ote:the resolution o! the "ait period is @@ microseconds on many systems >* million microseconds) * second?(+indo"s 1P does not support this interrupt >al"ays sets C7G*?(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ *6h 8 A5 G 00h ) get eystroe !rom eyboard >no echo?(

    return:

    A5 G 4IOS scan code(AL G ASCII character(>i! a eystroe is present, it is remo%ed !rom the eyboard bu!!er?(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ *6h 8 A5 G 0*h ) chec !or eystroe in the eyboard bu!!er(

    return:

    M7 G * i! eystroe is not a%ailable(

    COLLEGE OF COMPUTER STUDIES PA *@

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    18/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    M7 G 0 i! eystroe a%ailable(A5 G 4IOS scan code(AL G ASCII character(>i! a eystroe is present, it is not remo%ed !rom the eyboard bu!!er?(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ *h ) system reboot(

    3sually, the 4IOS "ill try to read sector *, head 0, trac 0 !rom dri%e A: to 0000h:@C00h( heemulator Qust stops the e'ecution, to boot !rom !loppy dri%e select !rom the menu: %irtual dri%e)T boot !rom !loppy

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ *Ah 8 A5 G 00h ) get system time(

    return:

    C1:.1 G number o! cloc tics since midnight(AL G midnight counter, ad%anced each time midnight passes(

    notes:there are appro'imately *(-06

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    19/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    entry: .L G character to "rite, a!ter e'ecution AL G .L(

    e'ample:

    mo% ah, -

    mo% dl, aint -*h

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G= ) output character to printer(entry: .L G character to print, a!ter e'ecution AL G .L(

    e'ample:

    mo% ah, =mo% dl, aint -*h

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G6 ) direct console input or output(

    parameters !or output: .L G 0((-=< >ascii code?parameters !or input: .L G -==

    !or output returns: AL G .L!or input returns: M7 set i! no character a%ailable and AL G 00h, M7 clear i! character a%ailable(

    AL G character read& bu!!er is cleared(

    e'ample:

    mo% ah, 6mo% dl, aint -*h & output character(

    mo% ah, 6mo% dl, -==int -*h & get character !rom eyboard bu!!er >i! any? or set M7G*(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G@ ) character input "ithout echo to AL(i! there is no character in the eyboard bu!!er, the !unction "aits until any ey is pressed(

    COLLEGE OF COMPUTER STUDIES PA *

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    20/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    e'ample:

    mo% ah, @int -*h

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G ) output o! a string at .S:.1( String must be terminated by U(

    e'ample:

    org *00hmo% d', o!!set msgmo% ah, int -*h

    retmsg db Rhello "orld UR))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G0Ah ) input o! a string to .S:.1, !ist byte is bu!!er size, second byte is number o!chars actually read( this !unction does not add U in the end o! string( to print using I$ -*h 8

    A5G you must set dollar character at the end o! it and start printing !rom address .S:.1 H -(

    e'ample:

    org *00hmo% d', o!!set bu!!ermo% ah, 0ahint -*h

    Qmp printbu!!er db *0,V, *0 dup> ?print:'or b', b'mo% bl, bu!!erW*Xmo% bu!!erWb'H-X, Umo% d', o!!set bu!!er H -mo% ah, int -*hret

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G04h ) get input status&returns: AL G 00h i! no character a%ailable, AL G 077h i! character is a%ailable(

    COLLEGE OF COMPUTER STUDIES PA -0

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    21/59

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    22/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    I$ -*h 8 A5G 2h ) mae directory(entry: .S:.1 )T ASCIM pathname& zero terminated string, !or e'ample:

    org *00h

    mo% d', o!!set !ilepathmo% ah, 2hint -*h

    ret

    !ilepath .4 RC:YmydirR, 0 & path to be created(end

    the abo%e code creates c:Yemu06Y%dri%eYCYmydir directory i! run by the emulator(

    9eturn: C7 clear i! success!ul A1 destroyed( C7 set on error A1 G error code($ote: all directories in the gi%en path must e'ist e'cept the last one(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G 2Ah ) remo%e directory(

    ntry: .S:.1 )T ASCIM pathname o! directory to be remo%ed(

    9eturn:

    C7 is clear i! success!ul, A1 destroyed C7 is set on error A1 G error code(

    $otes: directory must be empty >there should be no !iles inside o! it?(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G 24h ) set current directory(

    ntry: .S:.1 )T ASCIM pathname to become current directory >ma' 6< bytes?(

    9eturn:

    Carry 7lag is clear i! success!ul, A1 destroyed(Carry 7lag is set on error A1 G error code($otes: e%en i! ne" directory name includes a dri%e letter, the de!ault dri%e is not changed,only the current directory on that dri%e(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    COLLEGE OF COMPUTER STUDIES PA --

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    23/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    I$ -*h 8 A5G 2Ch ) create or truncate !ile(

    entry:

    C1 G !ile attributes:

    mo% c', 0 & normal ) no attributes(mo% c', * & read)only(mo% c', - & hidden(mo% c', < & systemmo% c', @ & hidden, system and read)onlymo% c', *6 & archi%e

    .S:.1 )T ASCIM !ilename(

    returns:

    C7 clear i! success!ul, A1 G !ile handle(C7 set on error A1 G error code(

    note: i! speci!ied !ile e'ists it is deleted "ithout a "arning(

    e'ample:

    org *00hmo% ah, 2chmo% c', 0mo% d', o!!set !ilenamemo% ah, 2chint -*h

    Qc errmo% handle, a'

    Qmp !ilename db Rmy!ile(t'tR, 0handle d" Verr:& ((((:ret

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G 2.h ) open e'isting !ile(

    ntry:

    COLLEGE OF COMPUTER STUDIES PA -2

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    24/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    AL G access and sharing modes:

    mo% al, 0 & read

    mo% al, * & "ritemo% al, - & read8"rite

    .S:.1 )T ASCIM !ilename(

    9eturn:

    C7 clear i! success!ul, A1 G !ile handle(C7 set on error A1 G error code(

    note *: !ile pointer is set to start o! !ile(note -: !ile must e'ist(

    e'ample:

    org *00hmo% al, -mo% d', o!!set !ilenamemo% ah, 2dhint -*h

    Qc errmo% handle, a'

    Qmp !ilename db Rmy!ile(t'tR, 0handle d" Verr:& ((((:ret

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G 2h ) close !ile(

    ntry: 41 G !ile handle

    9eturn:

    C7 clear i! success!ul, A1 destroyed(

    COLLEGE OF COMPUTER STUDIES PA -

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    25/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    C7 set on error, A1 G error code >06h?(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G 27h ) read !rom !ile(

    ntry:

    41 G !ile handle(C1 G number o! bytes to read(.S:.1 )T bu!!er !or data(

    9eturn:

    C7 is clear i! success!ul ) A1 G number o! bytes actually read& 0 i! at O7 >end o! !ile? be!orecall(

    C7 is set on error A1 G error code(

    $ote: data is read beginning at current !ile position, and the !ile position is updated a!ter asuccess!ul read the returned A1 may be smaller than the reuest in C1 i! a partial readoccurred(

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    26/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    .S:.1 )T ASCIM !ilename >no "ildcards, but see notes?(

    return:

    C7 clear i! success!ul, A1 destroyed( AL is the dri%e o! deleted !ile >undocumented?(C7 set on error A1 G error code(

    $ote: .OS does not erase the !iles data& it merely becomes inaccessible because the 7Achain !or the !ile is cleared deleting a !ile "hich is currently open may lead to !ilesystemcorruption()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ -*h 8 A5G

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    27/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    mo% ah, ?

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))I$ -*h 8 A5G 00h G de!ault, 0*h G A:, etc?

    .S:SI )T 607h?

    $otes:

    the returned path does not include a dri%e and the initial bacslash())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))I$ -*h 8 A5Gstop program?())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    COLLEGE OF COMPUTER STUDIES PA -@

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    28/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    I$ -*h 8 A5G =6h ) rename !ile 8 mo%e !ile(

    ntry:

    .S:.1 )T ASCIM !ilename o! e'isting !ile(

    S:.I )T ASCIM ne" !ilename(

    9eturn:

    C7 clear i! success!ul(C7 set on error, A1 G error code(

    $ote: allo"s mo%e bet"een directories on same logical dri%e only& open !iles should not berenamed))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    /ouse 1ri&er i#terru"ts INT **3

    ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))I$ 22h 8 A1G0000 ) mouse ininialization( any pre%ious mouse pointer is hidden(

    returns:i! success!ul: A1G07777h and 41Gnumber o! mouse buttons(i! !ailed: A1G0e'ample:

    mo% a', 0int 22h

    see also: mouse(asm in e'amples())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    (I$ 22h 8 A1G000* ) sho" mouse pointer(

    e'ample:

    mo% a', *int 22h ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))I$ 22h 8 A1G000- ) hide %isible mouse pointer(

    e'ample:

    mo% a', -

    COLLEGE OF COMPUTER STUDIES PA -

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    29/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    int 22h))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

    I$ 22h 8 A1G0002 ) get mouse position and status o! its buttons(

    returns:i! le!t button is do"n: 41G*i! right button is do"n: 41G-i! both buttons are do"n: 41G2C1 G '.1 G ye'ample:

    mo% a', 2int 22h

    & note: in graphical 2-0'-00 mode the %alue o! C1 is doubled(

    Program Segmentation Controls

    Segments in assembly

    >Simple hello "orld program "ritten in (model !ormat?

    his program is di%ided into three segments, namely, one stac segment,

    OTHER ASSEMBLER DIRECTI7ES

    SMBOL DEINITION DIRECTI7E) the symbol de!inition directi%es assign a symbolic name to an e'pression( his may be a bitconstant, an address re!erence, another symbolic name, a segment identi!ier >pre!i'? and anoperand or an instruction label( A!ter assigning the name you can use it any"here you "ouldnormally use the e'pression(he [3 >eual and G >eual sign? directi%es are similar but& *( ;ou can rede!ine symbol de!ined "ith G "hile symbols de!ined "ith [3 is permanent( -( [3 can be used !or "hether te't or a numeric e'pression, "hile G can be used

    only !or numeric e'pression(

    COLLEGE OF COMPUTER STUDIES PA -

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    30/59

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    31/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    OPERANDS

    *( ALI$);P) speci!ies at "hat ind o! boundary the segment is to start "hen it is stored inmemory( ;ou can mae it begin any"here >4;?, at e%en)numbered address >"ord?(or at an

    address that is di%isible by either *6 >para? or -=6>page?

    -( CO/4I$);P)speci!ies ho" a segment is to be combined "ith other o! the same name(Code, data and e'tra segments any be Qoined >P34LIC? or o%erlapped >CO/)/O$? stacsegments must ha%e the type SAC(

    2( CLASS D a!!ects the order in "hich segments are stored( Segments ha%ing the same classname are stored consecuti%ely, "hile those "ith di!!erent names are stored in the order theprogram building program >the liner? encounters them(

    '(

    .S S/$ PA9A P34LIC \.AAA .4 V4 .4 VS[3A9S .4 *,

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    32/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    A 7A9 procedure can be called !rom any code segment(

    ETERAL REERENCE DIRECTI7E

    hose directi%es allo" you to share in!ormation bet"een modules that you "ill e%entuallylin to !rom a program(

    P34LIC directi%e maes one or more symbol>s? a%ailable to other modules that "ille%entually lined to this one(

    19$ is the partner to public( It tells the liner to locate the needed module by re!erringto it(

    7O9/A:

    19$ name: typeW(]X

    +here name:

    *( a symbol in a data segment o! e'tra segment, then type an be byte, "ord or .+O9.-( A procedure label, then type can be $A9 or 7A92( A constant de!ined by an [3 or G directi%es

    INCLUDE DIRECTI7ES

    /erge >reads an entire !ile source statement into the current source !ile at assembly time('(

    I$CL3. 4: O597IL(asm

    his e'ample reads the contents o! the !ile O597IL(asm on dri%e 4 into your source !ile(

    ASSEMBL CONTROL DIRECTI7ES

    $. directi%e mars the end o! a program and this tells the assembler "here to stopassembling(

    O9 >Origin? pseudo D op alters the location, to mae the assembler store data orinstruction some places other than "here it normally stores them( O9 is most o!ten used inCO/ >command? type program(

    7ormat:

    O9 *005

    COLLEGE OF COMPUTER STUDIES PA 2-

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    33/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    INTRODUCTION TO 9 INSTRUCTION SET

    MO7 INSTRUCTION

    Can trans!er a byte or "ord bet"een a register and a memory location or bet"een t"o

    registers( It can also copy an immediate %alue >constant *? into a register or memory location(

    7ormat:

    /O# destination, source

    here are a !e" things you cannot do "ith a /O# instruction:

    *( ;ou cannot mo%e data bet"een t"o memory locations directly( Instead you must mo%ethe source data into a general D purpose register then mo%e that register into thedestination(

    '(/O# A1, PO3$.S/O# +I5, A1

    -( ;ou cannot load a constant into a segment register directly D as "ith rule ^*'(

    /O# A1, .S/O# .1, A1

    2( ;ou cannot mo%e the contents o! on segment register into another directly('(

    /O# A1, S/O# .S, A1

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    34/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    Once the interrupt handler !inishes, the processor continues "ith the program that "as inprogress(

    7rom the point o! %ie" o! the processor, starting an interrupt handler is much lie startinga called procedure( he main di!!erent is that, be!ore Qumping to the beginning o! the

    interrupt handler, the processor must sa%e enough in!ormation to restart the currentprogram( In particular, the processor must sa%e the !lags and the !ull address o! the ne'tinstruction is the current program(

    7ormat:

    I$ Zinterrupt typeT

    +here interrupt type is the identi!ication number o! one o! -= di!!erent %ectors in memory

    +hen the processor e'ecutes I$, it does the !ollo"ing

    *( pushes the !lags register onto the stac-( Clear the rap 7lag >7? and the Interrupt nable8.isable 7lag >I7?, to disable single)

    stepping and Jcoc outK other masable interrupts(2( Pushes the CS register onto the stac

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    35/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    INSTRUCTION SET

    BRANCH INSTRUCTION

    Co#1itio#4l Ju/"s

    COLLEGE OF COMPUTER STUDIES PA 2=

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    36/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    3nlie B/P instruction that does an unconditional Qump, there are instructions that do aconditional Qumps >Qump only "hen some conditions are in act?( hese instructions are di%ided inthree groups, !irst group Qust test single !lag, second compares numbers as signed, and thirdcompares numbers as unsigned(

    7O9/A:

    ZQump instructionT Zshort)labelT

    he operand !rom short)label tells you that the target label o! the Qump must be no more than)*- bytes to H *-@ bytes a"ay !rom the conditional trans!er instruction

    Ju/" i#stru!tio#s t34t test si#5le 2l45

    COLLEGE OF COMPUTER STUDIES

    Instruction .escription ConditionOppositeInstruction

    BM , BBump i! Mero>ual?( M7 G * B$M, B$

    BC , B4, B$A

    Bump i! Carry>4elo", $ot Abo%eual?( C7 G * B$C, B$4, BA

    BS Bump i! Sign( S7 G * B$SBO Bump i! O%er!lo"( O7 G * B$O

    BP, BPBump i! Parity%en( P7 G * BPO

    B$M , B$Bump i! $ot Mero>$ot ual?( M7 G 0 BM, B

    B$C , B$4, BA

    Bump i! $ot Carry>$ot 4elo", Abo%eual?( C7 G 0 BC, B4, B$A

    B$S Bump i! $ot Sign( S7 G 0 BS

    B$OBump i! $otO%er!lo"( O7 G 0 BO

    BPO, B$PBump i! Parity Odd>$o Parity?( P7 G 0 BP, BP

    PA 26

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    37/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    Ju/" i#stru!tio#s 2or si5#e1 #u/$ers

    Instruction .escription Condition

    Opposite

    Instruction

    B , BMBump i! ual >G?(

    M7 G * B$, B$MBump i! Mero(

    B$ , B$M

    Bump i! $ot ual>ZT?(

    M7 G 0 B, BMBump i! $ot Mero(

    B , B$L

    Bump i! reater >T?( M7 G 0

    B$, BL

    Bump i! $ot Less orual >not ZG?( and S7 G O7

    BL , B$

    Bump i! Less >Z?(

    S7 ZTO7 B$L, B

    Bump i! $ot reateror ual >not TG?(

    B , B$LBump i! reater orual >TG?( S7 G O7 B$, BL

    Ju/" i#stru!tio#s 2or u#si5#e1 #u/$ers

    Instruction .escription ConditionOppositeInstruction

    B , BM

    Bump i! ual>G?(

    M7 G * B$, B$MBump i! Mero(

    B$ , B$M

    Bump i! $otual >ZT?(

    M7 G 0 B, BMBump i! $otMero(

    BA , B$4 Bump i! Abo%e>T?( C7 G 0

    B$A, B4

    Bump i! $ot4elo" or

    and

    COLLEGE OF COMPUTER STUDIES PA 2@

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    38/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    ual >notZG?( M7 G 0

    B4 , B$A,BC

    Bump i! 4elo">Z?(

    C7 G * B$4, BA, B$C

    Bump i! $otAbo%e orual >notTG?(Bump i! Carry(

    U#!o#1itio#4l %u/"s

    he basic instruction that trans!ers control to another point in the program is B/P(

    he basic synta' o! B/P instruction:B/P labelo declare a label in your program, Qust type its name and add R:R to the end, label can be anycharacter combination but it cannot start "ith a number, !or e'ample here are 2 legal labelde!initions:label*:label-:a:Label can be declared on a separate line or be!ore any other instruction, !or e'ample:'*:/O# A1, *

    '-: /O# A1, -

    heres an e'ample o! B/P instruction:

    org *00h

    mo% a', = & set a' to =(mo% b', - & set b' to -(

    Qmp: calc & go to calc(

    bac: Qmp stop & go to stop(

    calc:add a', b' & add b' to a'(

    Qmp bac & go bac(

    stop:

    COLLEGE OF COMPUTER STUDIES PA 2

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    39/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    ret & return to operating system(

    O! course there is an easier "ay to calculate the some o! t"o numbers, but its still a goode'ample o! B/P instruction(

    As you can see !rom this e'ample B/P is able to trans!er control both !or"ard and bac"ard( Itcan Qump any"here in current code segment >6=,=2= bytes?(

    LOOPING INSTRUCTION

    LOOP is a seuence o! instruction that is e'ecuted repeatedly( he LOOP instructioncreates a loop that is to be e'ecuted a speci!ic number o! times(

    7O9/A:

    LOOP ZlabelT

    he loop instruction uses the C1 register as a counter that eeps trac o! ho" manytimes the LOOP is to be e'ecuted(

    /o% c' , Zloop countT

    ZLabelT:&& 4loc o! statement&LOOP ZlabelT

    Loo" I#stru!tio#

    I#stru!tio# o"er4tio# 4#1 %u/" !o#1itio# o""osite i#stru!tio#

    LOOPdecrease c', Qump to label i! c'not zero( .C C1 and BC1M

    LOOP decrease c', Qump to label i! c'not zero and eual >z! G *?( LOOP$

    LOOP$decrease c', Qump to label i! c'not zero and not eual >z! G 0?( LOOP

    LOOP$Mdecrease c', Qump to label i! c'not zero and z! G 0( LOOPM

    LOOPMdecrease c', Qump to label i! c'not zero and z! G *( LOOP$M

    COLLEGE OF COMPUTER STUDIES PA 2

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    40/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    BC1M Qump to label i! c' is zero( O9 C1, C1 and B$M

    ARITHMETIC INSTRUCTIONS

    ADD, ADC, SUB, SBB

    hese types o! operands are supported:

    9, memorymemory, 99, 9memory, immediate9, immediate

    9: A1, 41, C1, .1, A5, AL, 4L, 45, C5, CL, .5, .L, .I, SI, 4P, SP(

    memory: W41X, W41HSIH@X, %ariable, etc(((

    immediate: =, )-

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    41/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    SUB) Subtract second operand to !irst(

    Subtract(

    Algorithm:

    operand* G operand* ) operand-

    'ample:/O# AL, =S34 AL, * & AL G so eual?

    MUL, IMUL, DI7, IDI7

    hese types o! operands are supported:

    9memoryREG:A1, 41, C1, .1, A5, AL, 4L, 45, C5, CL, .5, .L, .I, SI, 4P, SP(

    /e/or0: W41X, W41HSIH@X, %ariable, etc(((

    COLLEGE OF COMPUTER STUDIES PA

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    42/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    MULand IMULinstructions a!!ect these !lags only: C, O+hen result is o%er operand size these !lags are set to (, "hen result !its in operand size these!lags are set to 9(

    7or DI7and IDI7!lags are unde!ined(

    MUL) 3nsigned multiply:

    "hen operand is a $0te:A1 G AL N operand(

    "hen operand is a ;or1:>.1 A1? G A1 N operand(

    IMUL) Signed multiply:

    "hen operand is a $0te:A1 G AL N operand(

    "hen operand is a ;or1:>.1 A1? G A1 N operand(

    DI7) 3nsigned di%ide:

    "hen operand is a $0te:

    AL G A1 8 operandA5 G remainder >modulus?( (

    "hen operand is a ;or1:A1 G >.1 A1? 8 operand.1 G remainder >modulus?( (

    IDI7) Signed di%ide:

    "hen operand is a $0te:AL G A1 8 operand

    A5 G remainder >modulus?( (

    "hen operand is a ;or1:A1 G >.1 A1? 8 operand.1 G remainder >modulus?( (

    COLLEGE OF COMPUTER STUDIES PA

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    43/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    INC, DEC, NOT, NEG

    hese types o! operands are supported:

    9

    memoryREG:A1, 41, C1, .1, A5, AL, 4L, 45, C5, CL, .5, .L, .I, SI, 4P, SP(

    /e/or0: W41X, W41HSIH@X, %ariable, etc(((

    INC, DECinstructions a!!ect these !lags only: Z, S, O, P, A(

    NOTinstruction does not a!!ect any !lags

    NEGinstruction a!!ects these !lags only: C, Z, S, O, P, A(

    NOT) 9e%erse each bit o! operand(

    NEG) /ae operand negati%e >t"os complement?( Actually it re%erses each bit o!operand and then adds * to it( 7or e'ample = "ill become )=, and )- "ill become -(

    MANIPULATING INSTRUCTION

    LOGICAL INSTRUCTION

    AND, TEST, OR, OR

    hese types o! operands are supported:

    9, memorymemory, 99, 9memory, immediate9, immediateREG: A1, 41, C1, .1, A5, AL, 4L, 45, C5, CL, .5, .L, .I, SI, 4P, SP(

    /e/or0: W41X, W41HSIH@X, %ariable, etc(((

    i//e1i4te: =, )-these instruction areused to mae decisions during program e'ecution?(

    AND) Logical A$. bet"een all bits o! t"o operands( hese rules apply:

    COLLEGE OF COMPUTER STUDIES PA

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    44/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    * A$. * G ** A$. 0 G 00 A$. * G 00 A$. 0 G 0

    As you see "e get (only "hen both bits are ((

    TEST) he same as ANDbut 2or 2l45s o#l0(

    OR) Logical O9 bet"een all bits o! t"o operands( hese rules apply:

    * O9 * G ** O9 0 G *0 O9 * G *0 O9 0 G 0

    As you see "e get (e%ery time "hen at least one o! the bits is (( OR) Logical 1O9 >e'clusi%e O9? bet"een all bits o! t"o operands( hese rules apply:

    * 1O9 * G 0* 1O9 0 G *0 1O9 * G *0 1O9 0 G 0

    SHIT INSTRUCTION

    SHL, SHR, SAL, SARhese types o! operands are supported:

    memory, immediate9, immediate

    memory, CL9, CL

    SHL Shi!t operand* Le!t( he number o! shi!ts is set by operand-(

    Algorithm: Shi!t all bits le!t, the bit that goes o!! is set to C7( Mero bit is inserted to the right)most position(

    'ample:/O# AL, ***00000bS5L AL, * & AL G **000000b, C7G*(

    C O

    COLLEGE OF COMPUTER STUDIES PA

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    45/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    r r

    O7G0 i! !irst operand eeps original sign(SHR ) Shi!t operand* 9ight( he number o! shi!ts is set by operand-(

    Algorithm:

    Shi!t all bits right, the bit that goes o!! is set to C7( Mero bit is inserted to the le!t)most position(

    'ample:/O# AL, 00000***bS59 AL, * & AL G 000000**b, C7G*(

    C O

    r r

    O7G0 i! !irst operand eeps original sign(

    SAL ) Shi!t Arithmetic operand* Le!t( he number o! shi!ts is set by operand-(

    Algorithm:

    Shi!t all bits le!t, the bit that goes o!! is set to C7( Mero bit is inserted to the right)most position(

    'ample:/O# AL, 00h & AL G ***00000b

    SAL AL, * & AL G **000000b, C7G*(9

    C O

    r r

    O7G0 i! !irst operand eeps original sign(

    SAR) Shi!t Arithmetic operand* 9ight( he number o! shi!ts is set by operand-(

    Algorithm:

    Shi!t all bits right, the bit that goes o!! is set to C7( he sign bit that is inserted to the le!t)most position has the same %alue as be!ore shi!t(

    'ample:/O# AL, 00h & AL G ***00000bSA9 AL, * & AL G ****0000b, C7G0(

    /O# 4L,

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    46/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    SA9 4L, * & 4L G 00*00**0b, C7G0(

    9

    C O

    r r

    O7G0 i! !irst operand eeps original sign(

    ROTATING INSTRUCTION

    RCR, RCL, ROR, ROLhese types o! operands are supported:

    memory, immediate9, immediate

    memory, CL9, CL

    RCR) 9otate operand* right through Carry 7lag( he number o! rotates is set by operand-(

    Algorithm:

    shi!t all bits right, the bit that goes o!! is set to C7 and pre%ious %alue o! C7 is inserted tothe le!t)most position(

    'ample:SC & set carry >C7G*?(/O# AL, *Ch & AL G 000***00b9C9 AL, * & AL G *000***0b, C7G0(9

    C O

    r rO7G0 i! !irst operand eeps original sign(

    RCL) 9otate operand* le!t through Carry 7lag( he number o! rotates is set by operand-(+hen i//e1i4teis greater then *, assembler generates se%eral RCL 88, (instructionsbecause 06 has machine code only !or this instruction >the same principle "ors !or all othershi!t8rotate instructions?(

    COLLEGE OF COMPUTER STUDIES PA

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    47/59

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    48/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    O7G0 i! !irst operand eeps original sign(

    ADRESSING MODES

    ACCESSING MEMOR IN ASSEMBL

    o access memory n assembly, all you ha%e to remember is that memory is Qust onegiant array o! bytes, "hich you can access lie an array in most programming languages( he06 has *@ di!!erent "ays o! accessing memory "hich "e "ill discuss today(

    /O# Instruction

    4e!ore that, "e "ould lie to no" about the mo% instruction( he basic structure o! themo% instruction is:

    mo% destination, source& destinationGsource "here the %alue o! the source isassigned into the destination One o! the things to remember about the mo% instruction is that thedestination and the source operands must be o! the same size( ;ou cannot mo%e an )bitregister into a *6)bit register>mo% cl,a'? and %ice)%ersa(

    he

    reigister indirect addressing mode, instead o! using a *0)bit constant, uses a %alue in one o! the!ollo"ing registers:

    COLLEGE OF COMPUTER STUDIES PA

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    49/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    41 D e': mo% al, Wb'X

    4P D e': mo% al, WbpX

    SI D e': mo% al, WsiX

    .I D e': mo% al, WdiX

    4y de!ault, b', si, di o!!set ds "hile bp o!!sets ss>stac segment?( ;ou can use a segmenta o%erride pre!i', i! you "ant to change this

    /o% al,ss:Wb'X

    /o% al,ds:WdpX

    /o% al,ds:WbpX

    /o% al,cs:WsiX

    COLLEGE OF COMPUTER STUDIES PA

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    50/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    INDEED ADDRESSING MODE

    Inde'ed Addressing modes ha%e the !ollo"ing synta'

    /o% alm dispWb'X or mo% al, Wb'HdispXhis access ds:b'Hdisp >applies to si and di as "ell?

    /o% al, dispWbpX or mo% al, WbpHdispXhis access ss:bpHdispWspecial caseX

    /o% al, dispWsiX or mo% al, WsiHdispX/o% al, dispWdiX or mo% al, WdiHdispX

    +here disp is an or *6)bit %alue, in this case, the memory that is being accesses is at theo!!set number G b'Hdisp

    'ample:

    /o% b', o!!set msg/o% dl, JhK/o% 0h,Wb'X, dl & this "ill change Jhello "orldK to Jhello "orldK

    /o% dl, *hWb'X &this "ill sa%e JeK >==h?to dl >Jhello "orldK?

    /o% ahWb'X, JK &this "ill change Jhello"orldK to Jhello "orlK

    COLLEGE OF COMPUTER STUDIES PA =0

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    51/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    Wb'HdispX addressing modes

    BASED INDE ADDRESSING MODE

    4ased Inde' Addressing /ode maes use o! one base register >b' or bp? and one inde'register >si or di?

    /o% al, Wb'XWsiX access ds>b'Hsi?

    COLLEGE OF COMPUTER STUDIES PA =*

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    52/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    /o% al, WdiXWbpX access ss>diHbp?

    Addressing modes that "ill in%ol%e bp o!!set ss, but you can "rite segment o%errides( ;ou can"rite do"n a base register and an inde' register in any order(

    BASE INDE >ITH DISPLACEMENT ADDRESSING MODES

    4ased Inde' "ith .isplacement addressing mode is a slight modi!ication o! the 4aseInde' mode in%ol%ing the addition o! an )bit or *6)bit displacement %alue(

    /o% a', msgWb'XWsiX D gets t"o bytes starting !rom ds>b'HsiHo!!set msg?

    COLLEGE OF COMPUTER STUDIES PA =-

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    53/59

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    54/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    call cirstrgoto'y *0,-0"riteln str*int -*h

    cirstr Procmo% a',0002hint *0h

    retendpend mainend

    Di22ere#!e $et;ee# M4!ro 4#1 Pro!

    *( Place o! declaration

    -( In%oing process2( $ear and 7ar o! proc

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    55/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    ) 9ead and +rite Access

    o speci!y the !ilename to open, the path and !ilename is assigned to a string(he address o! the string is then assigned to the register pairs ds and d'( he segment o! p! the

    string is assigned to ds and the o!!set to d'( It should be noted that the !ilename is terminate thestring by a zero %alue(

    'ample:

    7ile* db prans,t't,o

    A!ter attempting to open the !ile, the interrupt -*h returns some %alues in C7>Carry 7lag?and a'( I! C7 is set *, an error occurred and the !ile "as ne%er opened( 5o"e%er, i! C7 is zero,opening "as success!ul and a' contains the !ile handle is used to re!erence the !ile(

    'ample:

    &headers(data&the !ollo"ing %ariables "ill be used throughout&this section

    7ile$ame db Ke't!ile(t'tK,07ilehandle d" 04u!!er db 200 dup>0?4ytes9ad d" 0

    7ileSize dd 0(code&]&initialization&]mo% ah,2dhmo% al,0 &Open !ile !or read onlymo% a',_datamo% ds,a'mo% d',o!!set 7ilename &assign the o!!set o! the string to d'int -*h &call interrupt -*h

    Qc 7ilerrorOpen &Qump to error label i! the carry !lag is setmo% W7ile5andleX,a'&assign the returned handle to %ariable 7ile5andle!ilerrorOpen&error handling section

    Closi#5 iles

    COLLEGE OF COMPUTER STUDIES PA ==

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    56/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    Since there is a !unction !or opening !iles, there is a counterpart !unction !or closing !iles(o access this !unction, the register ah is assigned the handle o! the !ile to be closed( his!unction !rees up the resources or memory used by .OS !or controlling a !ile( I! an error occurs,this !unctions sets the C7>carry !lag? to *( no other error details are gi%en by this !unction( Asample code closing a !unction is:

    /o% b',W7ile5andleX/o% ah,2ehInt -*h

    he %ariable 7ile5andle re!erenced here is the same gi%en in the pre%ious e'ample(

    Re41i#5 iles

    +hen !iles are created, !iles are assigned speci!ic attributes, hidden, read)only( o read!iles, the !unction 2!h o! interrupt -*h is used( o utilize !unction ah is assigned 2!h( he register

    b' is then assigned the !ile handle o! a pre%iously opening !ile( o speci!y the number o! bytes toread, the reuired number is assigned to c'( he bytes read !rom the !ile are then "ritten to theaddress speci!ied by the registers ds and d'( ds and d' contains the segment and d' the o!!seto! the data(

    he !unction returns the actual bytes "ritten to the !ile by the register a'( enerally, i! thebytes reuested to be "ritten and actual number di!!ers, an error occurred( A sample clips isgi%en belo":

    mo% b', W7ile5andleXmo% b', csmo% ds, a'mo% d', o!!set bu!!ermo% ah,

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    57/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    7ALUE ACCESS MODES

    9 9ead Only

    ( 5idden

    ) System

    * #olume Label

    + Sub)directory

    - Archi%e

    #olume labels are special types o! !iles "herein they do not occupy space( hey are

    representing the label name o! a dis or !loppy( It should be noted that read)only and hidden

    !iles couldnt de deleted outright( he hidden are read)only attributes should be !irst unset be!oredeletion can occur( Lie in opening !iles, the !ilename are speci!ied by using registers ds and d'(hey are assigned the address o! the !ilename in ASCII notation( he interrupt returns %alues inC7>Carry 7lag? the register a'( I! C7 is set to, an error occurred and !ile "as not created( On theother hand i! C7 is 0, the register a' contains the !ile handle o! the ne"ly created !ile(

    'ample:

    &]mo% ah,2chmo% a',_data

    mo% ds,a'mo% d',o!!set 7ile$amemo% c',0 &no attributeint -*hmo% W7ile5andleX,a' &get !ile handle&]7ilerrorCreate&rror 5andling routine&]

    Deleti#5 iles

    As !iles can be created, they can also be deleted( .eletion is achie%ed by !unction

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    58/59

    CSCI06Computer Organization, Architecture and Assembly Language Prepared by: MELJUN P. CORTES

    ERROR CODE ERROR

    ) 7ile not 7ound

    * Path $ot 7ound

    - Access .enied

    'ample:

    &]mo% ah,

  • 8/13/2019 MELJUN CORTES MANUAL Computer Organization Assembly Lang CSCI06

    59/59