Miscellaneous > 16 bit DOS Programming

Choice of .model affects the output of program

(1/2) > >>

Hedegaard:
Hello

I'm new to Assembly and am following a tutorial on youtube (https://www.youtube.com/watch?v=pMzjKkj1ldk&list=PLPedo-T7QiNsIji329HyTzbKBuCAHwNFC&t=1m54s).

The purpose of the current part of the tutorial is to show how the .data section works and how ASCII values are used. However, when I run the program of the tutorial (included below), it prints out the symbol '²' instead of '2', which was what was supposed to be the output. The output in the youtube video does the same thing, but the guy doing the tutorial doesn't notice the difference between the two symbols.

In fact, no matter what I choose for the value of the variable "count1", it still outputs '²'. As someone else in the comments of the youtube video remarked, it works the way you want it to, if you replace ".model small" by ".model tiny". What is going on here?


--- Code: ---.model small
.data

    count1 db 2

.code

main proc
   
    mov dl, count1  ; Input character to dl
   
   
    add dl, 48 ; add 48 to dl
    mov ah, 2h ; Code for write character
   
    int 21h    ; Display character in dl
   
endp

end main
--- End code ---

Best regards.

nidud:
you need to set DS to the data segment first.
try this:

--- Code: ---    mov ax,SEG _DATA
    mov ds,ax
    mov dl, count1  ; Input character to dl

--- End code ---

or


--- Code: ---    mov ax,@data

--- End code ---

Hedegaard:
nidud, thanks, though I cannot get it to work. I tried it, but now I get an output of 'á', which looks like it is ASCII character 160. If I change the .model to tiny, the output will be '0'. I'm not sure why the model affects the output.

My code is now:


--- Code: ---.model small
.data

    count1 db 4

.code

main proc
   
    mov ax, SEG _DATA
    mov ds, ax
   
    mov dl, count1  ; Input character to dl
   
   
    add dl, 48 ; add 48 to dl
    mov ah, 2h ; Code for write character
   
    int 21h    ; Display character in dl
   
endp

end main


--- End code ---

nidud:
You could try using @data instead of SEG _DATA. Using DGROUP should also work in that case.

nidud:
In the small model the stack is equal data so using SS should also work.

--- Code: ---    mov ax, ss
    mov ds, ax
    ..
    push ss
    pop ds

--- End code ---

Or simply use SS directly:

--- Code: ---    mov dl,ss:count1

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version