Re: 8086 Assembly Programming Help

From: flekso (taurus_at_email.hinet.hr)
Date: 04/05/04

  • Next message: C: "Re: Help understanding uops, etc..."
    Date: Mon, 5 Apr 2004 17:43:11 +0000 (UTC)
    
    

    "Steve, I-Net+" <aeroman10@yahoo.com> wrote in message
    news:b0d144cb.0404041245.268c6ca4@posting.google.com...
    > I am using DEBUG through MS-DOS to make and run a certain program.
    > I need to write a program through DEBUG that will do the following:
    >
    > 1. Input two one digit numbers from keyboard [A and B]
    > 2. Compare the numbers and display "First Larger" or "Second Larger"
    > 3. Add the numbers and display the sum
    > 4. Subtract the smaller from the larger and display the difference
    > 5. Multiply the numbers and display the product
    > 6. Divide the larger number by the smaller and display the quotient..
    >
    > Now my knowledge of assembly language is very limited, I havent taken
    > a class to learn it yet.
    > I know how to do the basic things like MOV, ADD, SUB but when it comes

    You don't need much more for this task (div,mul..)

    Calling interrupts goes like this:

    mov ah, function_number ; (list of functions can be found in the link
    bellow)
    int xx ; xx stands for interrupt number (21H for DOS, 10H for video, 13H
    for disk...)

    Sometimes you need to pass a couple of other parameters in registers
    al,dx,bx...
    And that's it, easier than calling windows api.
    For example, to print a string (masm format, for debug you'll use a
    subcommand for code and a subcommand + db subsubcommand for data, and keep
    track of all data and jump locations - forget all the labels and directives
    (stuff with '.' in front) - read: locate masm/tasm/nasm) :

    .model tiny ;one 64KB segment for code/data/stack

    .data ;segment
        SomeString db "Goodbye world$" ; has to be terminated with $
    (db goes for define byte)

    .code ;segment
    .startup
    main:
        mov ah,9 ; DOS function print string
    (9)
        mov dx, OFFSET SomeString ; dx carries the location of SomeString
        int 21H ; call DOS interrupt
    number

        mov ah,4cH ; DOS function to exit program
    (4c)
        int 21H

    end main ; terminates the asm source
    and points to the first instruction (label main:)

    Ralf Brown's interrupt list:
    http://www.ctyme.com/rbrown.htm
    http://www-2.cs.cmu.edu/afs/cs/user/ralf/pub/WWW/files.html

    To convert a number from binary integer to ascii:

        mov cx, 10 ; divisor
    i2a:
        mov dx, 0 ; don't need dx (in this case)
        mov ax, 13579 ; dividend
        div cx ; dx:ax pair is implied source/destination
    operand for word sized explicit operand (cx)
                                   ; couple of ns later... ax holds the
    quotient(1357); dx has modulo(9)
        or ax, 0 ; or instruction modifies flags (looking for
    ax=0, nothing more to divide) (or 0,0 is the only combination that results
    in 0)
        JNZ i2a ; Jump if Not Zero flag enabled (zero flag is
    activated if the result of an instruction is 0)

    This is how the results come out from the loop:
    start: ax=13579
    1. ax=1357, dx=9 ;last digit
    2. ax=135, dx=7
    3. ax=13, dx=5
    4. ax=1, dx=3
    5. ax=0, dx=1 ;first digit
                                ;or ax,0 = zero, JNZ jumps no more...

    So if you look from bottom to the top you get what you're looking for in dx,
    some minor adjustments required:
    ASCII is an unsigned byte sized standard (number 0-9 -> ascii 48-57 decimal,
    or 30-39 hex)
    To convert dx:
    add dx,30H ; if dx was 9 now it's 39(ascii 9)
    mov location, dl ;store the ascii digit
                                ;ascii is byte sized, dl is always enough for
    modulo of 10

    You'll need cmp instruction for your other chores. It also modifies the
    flags(by subtracting the operands but not storing the result!) so you can
    use it and Jxx (JNZ...) instructions to control the flow of your program.

    Newbie asm ( ! - based on tasm):
    http://atrevida.comprenica.com/gameprog.html

    Intel's instruction set (limited, but for this task it's just on cue, my
    biggest problem when i began asm programming was ubiquity of information
    available - just one more link... - click,click...)
    http://www.manualy.sk/intel/

    Debug.exe reference (you'll need a,e,g,t,p subcommands - at least):
    http://www.microsoft.com/resources/documentation/WindowsServ/2003/enterprise/proddocs/en-us/Default.asp?url=/resources/documentation/WindowsServ/2003/enterprise/proddocs/en-us/debug_subcmds.asp

    e to quickfix data
    a to enter/assemble instructions (db sub subcommand for data - it's up to
    you to worry about their location !)
    g to execute
    t to trace *each* instruction
    p to trace instructions except calls,loops,movs (useful for avoiding
    long/repetative parts of code not in the pivot of your attention)


  • Next message: C: "Re: Help understanding uops, etc..."

    Relevant Pages

    • [PATCH -tip -v13 01/11] x86: instruction decoder API
      ... This version introduces instruction attributes for decoding instructions. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
      (Linux-Kernel)
    • [PATCH -tip v14 01/12] x86: instruction decoder API
      ... This version introduces instruction attributes for decoding instructions. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
      (Linux-Kernel)
    • [PATCH 01/18] x86: Instruction decoder API
      ... Add x86 instruction decoder to arch-specific libraries. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
      (Linux-Kernel)
    • [PATCH -tip v6 1/5] x86: instruction decorder API
      ... This version introduces instruction attributes for decoding instructions. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
      (Linux-Kernel)
    • [PATCH -tip v6.1 1/5] x86: instruction decorder API
      ... This version introduces instruction attributes for decoding instructions. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
      (Linux-Kernel)