News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Choice of .model affects the output of program

Started by Hedegaard, July 15, 2017, 03:48:45 AM

Previous topic - Next topic

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?


.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

#1
deleted

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:

.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

#3
deleted

nidud

#4
deleted

RuiLoureiro

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

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

aw27

#7
Try this:


;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:

daydreamer

Welcome to forum :t
I recommend try masm32 and 32bit assembly
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

Quote from: daydreamer on June 21, 2018, 02:48:15 PM
Welcome to forum :t
I recommend try masm32 and 32bit assembly

That's a spam-bot.   8)

not a good one either. first link points to

http://%22https//jsonformatter-online.com/%22


notice the odd formatting? the second is screwed up as well. the third, well, has results.

jj2007

Quote from: Hedegaard on July 15, 2017, 05:53:14 AM
My code is now:
... almost perfect. You only need the 16-bit ExitProcess equivalent, and it works just fine:

.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

    mov ax, 4C00h ; ExitProcess, DOS style
    int 21h   

main endp

end main


It seems like a minor detail, but it isn't; without a proper exit, you get all kinds of weird output to the console.
I also added main before endp.

felipe

I think the old ml (for 16 bits) even has a directive that do exactly that (the exit app code in dos). I think is called EXIT. I also remembers that it had one to initialize the data section (loading ds with @data) but i'm not sure of the name of that directive. Both are in that old (i think is the only one) masm manual.  :idea: