Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Assembly language Loop (Debug.com)  (Read 11762 times)

0 Members and 1 Guest are viewing this topic.

jamescv31

    Topic Starter


    Greenhorn

    • Experience: Experienced
    • OS: Windows 7
    Assembly language Loop (Debug.com)
    « on: September 14, 2014, 06:44:43 AM »
    Greetings I have a question in assembly language debug.com (for anyone have any experience in assembly only): What will be the non fix loop when a user input a letter like "c" then the output must be "d" to "z"? I know the code already just asking what will be the loop for ending in z or Z.

    Code: [Select]
    here's my code:

    a 100
    mov ah, 01
    int 21
    mov bl, al
    mov ah, 02
    int 21
    mov dl, 0d
    int 21
    mov cl, 20
    mov dl, bl
    inc dl
    int 21
    loop 114
    int 20


    The problem arises is the iteration where the ending must be Z or z which I couldn't figured out based in HEX Ascii.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Assembly language Loop (Debug.com)
    « Reply #1 on: September 14, 2014, 11:36:58 AM »
    I can help you.
    Assembly language is used when needed. Otherwise ,modern desktops and laptops are so fast that thee is little reason to directly use assembly language.
    If you are new to programming, it is best to start  with something a little  up on the ladder. The C language is often given as starring place.  I would suggest something even easier to start with. Such as Python.
    But let's say you really want to do assembly. OK.
    First, document what you want to do.  Next, use codes that you  already know to get a working model. Then introduce a few new c concepts and try it out.

    For General Reference:
    http://en.wikipedia.org/wiki/X86_assembly_language
    Quote
    x86 assembly language is a family of backward-compatible assembly languages, which provide some level of compatibility all the way back to the Intel 8008. x86 assembly languages are used to produce object code for the x86 class of processors. Like all assembly languages, it uses short mnemonics to represent the fundamental instructions that the CPU in a computer can understand and follow. Compilers sometimes produce assembly code as an intermediate step when translating a high level program into machine code. Regarded as a programming language, assembly coding is machine-specific and low level. Assembly languages are more typically used for detailed and time critical applications such as small real-time embedded systems or operating system kernels and device drivers.
    I put that here so others know what we are talking  about.

    You description sounds like an input procedure where the user must enter a specific key from the keyboard.  You code does not look like an input routine.  Please clarify what you want to do and why you sue specific codes.

    If you are using Linux, you must use only 32 bit code. And if you have a 64bit Windows system you also must use either 32 code. Or else 64 bit code.
    Use you- can use  16 bit code only on 32 bit versions of Windows. Your code fragment did not say. Also, your ought to document with system calls your are using  with INT 21H  so that others can help you.

    Here is preference that explains why IN 21h is used in assembly:
    http://stackoverflow.com/questions/1245809/what-is-int-21h
    In general, that call should have two parameters in registers. One a byte value and the other a pointer. Faille to do that can have strange results.


    EDIT: If the OP is using MS-DOS or a compatible OS, he needs to understand the DOS API:
    http://en.wikipedia.org/wiki/MS-DOS_API

    My bad. I said byte value. It must be word value.
    « Last Edit: September 14, 2014, 12:01:22 PM by Geek-9pm »

    jamescv31

      Topic Starter


      Greenhorn

      • Experience: Experienced
      • OS: Windows 7
      Re: Assembly language Loop (Debug.com)
      « Reply #2 on: September 14, 2014, 11:41:35 PM »
      actually just wanted to know how to have a loop that ends only in Z when a user input any letter.


      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Assembly language Loop (Debug.com)
      « Reply #3 on: September 15, 2014, 07:09:01 AM »
      OK. But before trying a code fragment, we need a concise statement of what we want to do. It should be something g useful, me3inghfull or educational.
      The standard assembler will treat the ; as a comment
      Code: [Select]
      ; ******************
      ;     TEST.ASM
      ; a very simple test
      ; get a user input
      ; check to see if it is a Z
      ; in not increment,
      ;  otherwise  quit.
      ; *********************
      This is a standard way of doing documentation in assembler. In this kind of programming documentation should never be thought of a s an  option. Once you have a clear statement of intent and purpose, the code becomes easy.
      I did assembly programming years ago and had to work with other people. Documentation was part of the job description.

      Does the above describe what you intend? If so, I will show you the code. But if not,there is no point in showing you code for what you do not need.

      Unless you say otherwise, I well assume the environment is some version of MS-DOS  from 3 up running on an Intel 8086 or equal.



       


      jamescv31

        Topic Starter


        Greenhorn

        • Experience: Experienced
        • OS: Windows 7
        Re: Assembly language Loop (Debug.com)
        « Reply #4 on: September 16, 2014, 07:02:37 AM »
        Actually the mov ah, 01 tends to type an input by a letter. so if its enter "t" then the next line for result is "u" to "z". "c" then result is "d" to "z". Which the iteration of loop is not fix.

        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Assembly language Loop (Debug.com)
        « Reply #5 on: September 16, 2014, 09:20:17 AM »
        You can not use LOOP  in the debug  assembly.
        Use JNZ or JZ instead
        I will test your code and come back later today.



        jamescv31

          Topic Starter


          Greenhorn

          • Experience: Experienced
          • OS: Windows 7
          Re: Assembly language Loop (Debug.com)
          « Reply #6 on: September 16, 2014, 09:41:27 AM »
          Actually we are in the matter of looping, and not yet been discuss for us regarding to JNZ or JZ unless I'm gonna advance study however this is for our probably activity in class which no one could solve the algorithm.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Assembly language Loop (Debug.com)
          « Reply #7 on: September 16, 2014, 10:21:28 AM »
          So this is an exercise in an introductory course?
          Kindly Tell you instructor to get some material.
          Look for this:
          How to use debug to write very small com files

          These are links that take you  to  good  places.

          http://www.instructables.com/id/How-to-write-the-world-s-smallest-%22Hello-World!%22-e/

          http://en.wikipedia.org/wiki/Debug_%28command%29

          http://en.wikipedia.org/wiki/MS-DOS_API

          I have attached a script named test.txt but it does not work right.

          EDIT: Another link: 
          http://kipirvine.com/asm/debug/Debug_Tutorial.pdf



          [attachment deleted by admin to conserve space]

          jamescv31

            Topic Starter


            Greenhorn

            • Experience: Experienced
            • OS: Windows 7
            Re: Assembly language Loop (Debug.com)
            « Reply #8 on: September 16, 2014, 10:46:28 AM »
            Close enough but is there a possible to end in letter "z"?

            So that any letter to be input will be the output until z only. (b = c to z, r = s to z)

            However I couldn't get exact arithmetic problems based on ASCII.

            Geek-9pm


              Mastermind
            • Geek After Dark
            • Thanked: 1026
              • Gekk9pm bnlog
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Re: Assembly language Loop (Debug.com)
            « Reply #9 on: September 16, 2014, 12:19:04 PM »
            Here is the verified version of your code.
            Code: [Select]
            F0100 01FF 76
            A 100
            mov ah, 01 ; get input cahr
            int 21 ; system call
            mov dl, al ; copy char
            mov dh, dl ; save for return code
            push dx ; save it on stack
            mov ah, 02 ; do output char
            int 21 ; system call
            pop dx ; get it back
            mov al, dl   ; copy for compare
            inc dl ; bump up by one
            cmp al, 5A ; is it a Z?
            nop ; nothing does not change flags
            jnz 0108 ; **** not equal, loop  ****
            nop ; no op
            mov ax, 4C00 ; this is better exit code
            mov al, dh ; get user input charfor error code
            int 21 ; system end
            nop ; nothing
            db 'Z'
            nop ; nothing

            ntest.com
            rcx
            0100
            w
            q

            The blanks are needed for the script. The script command is:
            DEBUG <TEST.TXT
            which will create the file TEST.COM in your DOS directory

            The letter Z can be place in code with this:

              DB  'Z'

            which tells the assembler to reserve a data byte with the initial value of the ASCII letter Z.

            The file is also attached below.





            [attachment deleted by admin to conserve space]

            jamescv31

              Topic Starter


              Greenhorn

              • Experience: Experienced
              • OS: Windows 7
              Re: Assembly language Loop (Debug.com)
              « Reply #10 on: September 16, 2014, 06:09:54 PM »
              So it means that verified version of code will not loop. Once an input of a letter is entered? Because the only that someone stated for us is by having a arithmetic operation of CX will determine the until Z only.


              Geek-9pm


                Mastermind
              • Geek After Dark
              • Thanked: 1026
                • Gekk9pm bnlog
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 10
              Re: Assembly language Loop (Debug.com)
              « Reply #11 on: September 16, 2014, 06:59:11 PM »
              Unfortunately it is hard to document a debug script
              Here r is the explanation:

              ntest.com           ; name file as text.com
              rcx                     ; specify the cx register
              0100                  ; set it to 256 bytes
              w                        ; write it to the current drive and directory
              q                         ; quite debug and return to DOS


              This illustrates why anything more than  a fragment of code should be done with standard assembler. Like NASM, which is free.
              Did you try the code?
              The script creates TEST.COM
              Here is the output:
              Quote
              Microsoft Windows XP [Version 5.1.2600]
              (C) Copyright 1985-2001 Microsoft Corp.

              D:\BIN>test
              CCDEFGHIJKLMNOPQRSTUVWXYZ
              D:\BIN>

              With Caps On the user entered the letter C and the program generated the rest of the letters until Z was found. Now if he enters a lower case c,  you will get a surprize.


              jamescv31

                Topic Starter


                Greenhorn

                • Experience: Experienced
                • OS: Windows 7
                Re: Assembly language Loop (Debug.com)
                « Reply #12 on: September 16, 2014, 08:27:10 PM »
                Oh, well it works however is there a way using the syntax of CX? by using arithmetic cause that may cause problems if I will use the code and our instructor may not allowed it.

                Geek-9pm


                  Mastermind
                • Geek After Dark
                • Thanked: 1026
                  • Gekk9pm bnlog
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 10
                Re: Assembly language Loop (Debug.com)
                « Reply #13 on: September 16, 2014, 09:34:56 PM »
                CX does nothing in the code. The code finish as shown  below
                Code: [Select]
                mov ax, 4C00 ; this is better exit code
                mov al, dh ; get user input charfor error code
                int 21 ; system end
                The instructions after that a re divestitures to the DEBUG.EXE  program to create a executable file, namely TEST.COM 
                The command
                DEBUJG <TEST.TXT
                creates the file TEST.COM
                If you wish to continue using DEBUG, you must learn the syntax.
                Please show this thread to your instructor. You are getting free help from a retired professional 8086 coder. This is the best I can do for you.  :)

                jamescv31

                  Topic Starter


                  Greenhorn

                  • Experience: Experienced
                  • OS: Windows 7
                  Re: Assembly language Loop (Debug.com)
                  « Reply #14 on: September 16, 2014, 09:38:01 PM »
                  So it means its not possible to have CX/ Counter Register to show how many iterations and stop on Z?