Author Topic: Choice of .model affects the output of program  (Read 111 times)

Hedegaard

  • Regular Member
  • *
  • Posts: 2
Choice of .model affects the output of program
« on: July 15, 2017, 03:48:45 AM »
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: [Select]
.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

Best regards.
Using emu8086, v 4.08 (8086 microprocessor emulator).

nidud

  • Member
  • *****
  • Posts: 1294
    • https://github.com/nidud/asmc
Re: Choice of .model affects the output of program
« Reply #1 on: July 15, 2017, 04:07:37 AM »
you need to set DS to the data segment first.
try this:
Code: [Select]
    mov ax,SEG _DATA
    mov ds,ax
    mov dl, count1  ; Input character to dl

or

Code: [Select]
    mov ax,@data

Hedegaard

  • Regular Member
  • *
  • Posts: 2
Re: Choice of .model affects the output of program
« Reply #2 on: July 15, 2017, 05:53:14 AM »
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: [Select]
.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

Using emu8086, v 4.08 (8086 microprocessor emulator).

nidud

  • Member
  • *****
  • Posts: 1294
    • https://github.com/nidud/asmc
Re: Choice of .model affects the output of program
« Reply #3 on: July 15, 2017, 06:19:43 AM »
You could try using @data instead of SEG _DATA. Using DGROUP should also work in that case.

nidud

  • Member
  • *****
  • Posts: 1294
    • https://github.com/nidud/asmc
Re: Choice of .model affects the output of program
« Reply #4 on: July 15, 2017, 06:33:50 AM »
In the small model the stack is equal data so using SS should also work.
Code: [Select]
    mov ax, ss
    mov ds, ax
    ..
    push ss
    pop ds

Or simply use SS directly:
Code: [Select]
    mov dl,ss:count1

RuiLoureiro

  • Member
  • ****
  • Posts: 668
Re: Choice of .model affects the output of program
« Reply #5 on: July 15, 2017, 06:52:24 AM »
Hi Hedegaard,
                     Wellcome to the forum.

                     The example is too old DOS. If you want to learn asm, download MASM32 from top right.
                     There are a lot of examples and you may start to write your own examples and post it here.
                     See you  :t

felipe

  • Member
  • **
  • Posts: 197
  • Yeah, assembly is the best!
Re: Choice of .model affects the output of program
« Reply #6 on: July 15, 2017, 07:57:46 AM »
Hedegaard:
I seen that in the video the guy is using emu8086 or something like that and i searched for the syntax of that tool and is not the same as masm's syntax. In the sense that is more flexible and probably will allow you to write things that won't run in real machines (you have to consider the OS). If you want to learn assembly language, i strongly recommend you, (even if it is for 16 bit  DOS programs), to learn a real assembly language, like masm.  :icon14:

And welcome to this forum!  :t
Programmer from the keyboard...

aw27

  • Member
  • ***
  • Posts: 406
Re: Choice of .model affects the output of program
« Reply #7 on: July 15, 2017, 08:15:17 AM »
Try this:

Code: [Select]
;ml /c test.asm
;link16 test.obj

.186

.model  small

.stack  100h

.data
count1 db 2
 
.code

start:
mov   ax,seg count1
        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
 
mov  ax, 4c00h       ; terminate program
        int 21h
 
end start

Tested in DosBox and works  :biggrin:
« Last Edit: July 15, 2017, 04:35:18 PM by aw27 »