3

I am learning and I am a beginner in assembly language programming and we are currently learning about string printing and manipulating display memory. I'd like give the background before talking about the problem. We are making programs for the iapx88 (intel 8088) processor architecture, we are using the nasm assembler and the afd debugger. I use 32-bit Windows 7 Ultimate. My problem is that I can't execute any of the string printing programs in the command prompt, even though the code runs correctly in the debugger. The attached images will help explain the problem better. Our instructor told us to run a full-screen dos program (like the editor) or to run the .com file of the program in the afd before executing the program in Dos. Neither of those tips has helped me. Here's one of the string printing programs which we've written:

    ; program in assembly to display 'hello world' on screen
    [org 0x0100]
                     push cs
                     pop  ds
                     jmp  start

    message:         db   'hello world'      ; string to be printed
    length:          dw   11                 ; length of the string

   ; subroutine to clear the screen
   clrscr:         push es
                   push ax
                   push di

                   mov  ax, 0xb800
                   mov  es, ax             ; point es to video base
                   mov  di, 0              ; point di to top left column

   nextloc:        mov  word [es:di], 0x0720  ; clear next char on screen
                   add  di, 2              ; move to next screen location
                   cmp  di, 4000           ; has the whole screen cleared
                   jne  nextloc            ; if no clear next position

                   pop  di
                   pop  ax
                   pop  es
                   ret

    ; subroutine to print a string at top left of screen
    ; takes address of string and its length as parameters
    printstr:      push bp
                   mov  bp, sp
                   push es
                   push ax
                   push cx
                   push si
                   push di

                   mov  ax, 0xb800
                   mov  es, ax             ; point es to video base
                   mov  di, 0              ; point di to top left column
                   mov  si, [bp+6]         ; point si to string
                   mov  cx, [bp+4]         ; load length of string in cx
                   mov  ah, 0x07           ; normal attribute fixed in al

    nextchar:      mov  al, [si]           ; load next char of string
                   mov  [es:di], ax        ; show this char on screen
                   add  di, 2              ; move to next screen location
                   add  si, 1              ; move to next char in string
                   loop nextchar           ; repeat the operation cx times


                   pop  di
                   pop  si
                   pop  cx
                   pop  ax
                   pop  es
                   pop  bp
                   ret  4

    start:         call clrscr             ; call the subroutine

                   mov  ax, message
                   push ax                 ; push address of message
                   push word [length]      ; push message length
                   call printstr           ; call the printsr subroutine

                   mov  ax, 0x4c00         ; terminate program
                   int  0x21

This is how we have been told to make the .com file of the program:

nasm hello.asm -o hello.com -l hello.lst

I keep all the program files in the same folder 'Assembly' with the nasm assembler in my D: drive. And here's what happens when I try to execute the program in CMD: First I type the name of the program: (https://i.sstatic.net/ELiaF.png) After pressing 'Enter': (https://i.sstatic.net/bcX1H.png)

I hope I have explained my problem well enough. I have tried to google the solution of this problem but I couldn't find one. If you guys could help me and tell me what I am doing wrong with my code, I would be very thankful to you. Thanks.

1 Answer 1

3

You are using Windows to execute a DOS program. That may or may not work (it won't if you are using a 64 bit version of Windows). I suggest you to first run COMMAND.COM and then, from it, run your program.


UPDATE: I've just tried it but it didn't work. What did work is the following:

  1. Run COMMAND.COM
  2. Execute DEBUG program (the ancient DOS debugger)
  3. From the DEBUG prompt, issue command db800:0
  4. A hex dump of the text screen memory is shown: lots of 20 07 20 07 bytes
  5. Issue "q" command to quit DEBUG
  6. From the COMMAND.COM prompt, issue a CLS
  7. Run your program. It works!

Seems like if the DOS VM included in Windows doesn't map the text screen memory until a EXE program is executed. Will test your program again, but converted to an EXE application to see if I'm right.


UPDATE2: forget about the EXE/COM issue. It's not that. It's just that the DOS VM doesn't start in text mode 3, which is what you are using. To switch to text color mode, add at the beginning of your program, right before calling clrscr the following code:

mov ax,3
int 10h  ;select 80x25 color text mode
Sign up to request clarification or add additional context in comments.

2 Comments

So what mode is it using? +1
To my surprise, it's mode 3 what is reported (by peeking byte at 40h:49h or issuing int 10h, function 0xF), but the VM seems not to be aware of it until an explicit call to int 10h with AH=0 is performed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.