I try to run this code
data segment
v1 dw 1,2,3,4,4,3,2,1
v2 dw 0,0,0,0,0,0,0,0
data ends
code segment
start:
lea si,v1
lea di,v2
mov cx,8
et:
mov [edi],si ; here I changed di with edi because di is 16bit
add di,2
inc si ;,2
inc di ;,2
loop et
mov ah,4ch
int 21h
code ends
end start
I tried to remove loop et but the result is the same
Can someone give me a clue please?
Your code is basically 16-bit code. However, by inserting .586p before "data segment", it does compile assemble in 32-bit mode, and the OS may try to run it. It then crashes because edi is not 402010h as in lea edi, [402010] but rather 2010h as in lea di, [402010].
Make up your mind if you are coding for good ol' DOS or for 32-bit Windows.
P.S.: Welcome to the Forum :icon14:
Thanks!
I tried
public start
data segment
v1 dw 1,2,3,4,4,3,2,1
v2 dw 0,0,0,0,0,0,0,0
data ends
code segment
start:
lea si,v1
lea edi,v2
mov cx,8
et:
mov [edi],si ;,di
add edi,2
inc si ;,2
inc edi ;,2
loop et
mov ah,4ch
int 21h
code ends
end start
and it still crashes :(
Are you coding for 16-bit or for 32-bit?
It looks like you are trying to code for 16-bit.
Is so, try something like this:
public start
DOSSEG
.model small
.stack 100h
.186
data segment
v1 dw 1,2,3,4,4,3,2,1
v2 dw 0,0,0,0,0,0,0,0
data ends
code segment
start:
mov ax, @data
mov ds, ax ; set segment register
mov es, ax ; set segment register
lea si,v1
lea di,v2
mov cx,8
et:
mov [di],si ;,di
add di,2
inc si ;,2
inc di ;,2
loop et
mov ah,4ch
int 21h
code ends
end start
Quote from: cioltealin on May 20, 2018, 09:58:46 PM
and it still crashes :(
Sure it crashes. Your code runs in 32-bit land, and int 21h has no useful meaning for the OS 8)
This is homework, right? Your teacher didn't tell you anything about, for example, the .model directive?
Thanks,I want to make it for 32 bits,for 16 bits I get error at mov [di],si ,it says that di should be for 32 bit
I guess that even if I want to make it for 16 bits I have to use 32 bits because of the compiler
@jj2007
He just said to find and correct the errors,nothing about the .model directive
Quote from: cioltealin on May 20, 2018, 10:49:49 PM
He just said to find and correct the errors,nothing about the .model directive
I can imagine :P
Btw which IDE/editor are you using, and which assembler? Masm version 6.14 assembles your snippet "as is", but it clearly believes you want to create 32-bit code. To make it assemble as 16-bit code (and that's what it is), you need the extra stuff posted by José alias aw27, i.e.
.model small
.stack 100h
However, it will not run on any modern OS version :(
Quote from: jj2007 on May 20, 2018, 11:06:26 PM
Quote from: cioltealin on May 20, 2018, 10:49:49 PM
He just said to find and correct the errors,nothing about the .model directive
I can imagine :P
Btw which IDE/editor are you using, and which assembler? Masm version 6.14 assembles your snippet "as is", but it clearly believes you want to create 32-bit code. To make it assemble as 16-bit code (and that's what it is), you need the extra stuff posted by José alias aw27, i.e.
.model small
.stack 100h
However, it will not run on any modern OS version :(
I use the header from other exercises
.386 ;tried also with .186
.model flat, stdcall
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
includelib msvcrt.lib
extern exit: proc
I use notepad++ with an plugin made by the teacher for masm that is from 2013,the dll doesn't specify the version
For Masm (and its clones), .model flat, stdcall means 32-bit code. Your program is 16-bit code.
Why 16 bit can't run on 32 bits ?
Tried with small and worked,thanks!
Kinda hard for a simple example... :icon_rolleyes:
Its a choice you need to make, either you write 16 bit code OR you write 32 bit code. They have different architecture and memory addressing modes and are not compatible. Mixing 16 and 32 bit code is simply not possible. Why a teacher wants to teach 16 bit code does not make sense, none of the modern OS versions will run it, the last was Win98se which still supported COMMAND.COM and this is at best late 1998.
There is a 16 bit section in the forum if that is what you have to do otherwise you will need to start writing 32 bit code which is different.
Let me add a bit to the confusion hoping someone will become nuts today. :biggrin:
Quote
Why 16 bit can't run on 32 bits ?
Who said that? It can. Only under the flat model it can not.
And 32 bits can run under the .small, .medium, .large and other models and use the int 21. Is this what your teacher want? Do you know what he wants? Does he know what he wants? ::)
aw is correct here but only if you can find an OS that supports multiple memory models. Win32 uses a different architecture where you have linear addressing thus the FLAT memory model. Back in Win98se or the dreadful Millenium version that flopped you have a real mode DOS under the 32 bit but from Windows 2000 upwards the 16 bit sub system was not present and 16 bit real mode DOS will not run on a 32 bit protected mode OS version.
I gather you can find a 16 bit emulator and run old code but if you really want to run 16 bit real mode code, you need a 16 bit real mode OS and the last I remember from Microsoft was DOS 6.22 in about 1993-4.
The other thing you need to build 16 bit applications is an OMF linker as a COFF linker does not build 16 bit OMF files.
What our friend needs to do is ASK his teacher what OS version you are supposed to run AND what form of asm he is supposed to write, 16 or 32 bit code.
welcome to forum
,dont choose 16bit,its restricted by segmented code for access 640k+ memory.while 32bit you c allocte around 4gb if you run in a 64bit OS,it has restrictions on indirect adressing so,while in 32bit mode you are free to use any combinations,DOS 16bit emulator maybe not support latest opcodes,MMX etc,but 32bit mode does
if you have VC++ experience,you have access to same winapi functions thru a invoke macro
and what you want is write the best code you can to get A+,instead of waste effort and time on learn how to do things in obsolote OS(DOS),while you have more use of know how to whip up a 8k windows program
good luck
Hello, welcome
When you turn your computer on, processor is set to work on 'real' mode, this means 16 bits, the one that ms-dos works by default. So, we can code to change processor mode to work on 'protected' mode, this means 32 bits (windows and linux) and we can change to 'long' mode, this means 64 bits (windows and linux). I'm not talking that ms-dos can't work with 32 or 64 bits, yes, it can, of course, if hardwired. Some processor instructions need priviledge to be used on 32 bits per example while on ms-dos not. An example is 'in' and 'out' instructions. You also have other modes like 'virtual', ..., but not the subject.
Your code use 'int 21h', this means that you need create a program to work on ms-dos because ms-dos offers to us programmers these routines (think like library or dll on windows side). Again, you have used on your program the function (routine) 4ch, this is an end routine or on other words, end my program and give control back to O.S.
By this, you need create an .exe file instead of .com file because .com program use int 20h as an end function.
Said this, and going back to past, a .com program is by default done to little programs, by default a mix of data and code. We have 16 bits of address space, this means that our program can have a size of 65535 bytes, or 64k. When we need more space to our program, we need more memory addresses. On that time each 'segment' can hold 64k bytes, so we need more segments inside our program if our program grow and switch between these segments to access data or code. On 32 bits each segment can hold 4gb (flat model), so we can forget about segments and offsets if our program size is below 4gb.
When ms-dos loaded a .com program it created on memory a PSP. This PSP need a size of 100h bytes on memory loaded before our program.( you can use org 100h, or stack 100h, ... ).
Your example have code and data segment, you can choose to mix both into only one segment and create a .com file (change ms-dos 'end' function properly). You can create an .exe file and set segments by using some registers segment (.model directive).
Have a lot of examples on old board and inside this new board on ms-dos section, enjoy.
i don't know what assembler you are using - it doesn't seem to be MASM
if you use MASM and a 16-bit linker, this should work
.MODEL Small
.STACK 4096
.DOSSEG
.386
OPTION CaseMap:None
;####################################################################################
.DATA
s$Msg db 'Hello World !',0Dh,0Ah,24h
;************************************************************************************
.DATA?
;####################################################################################
.CODE
;************************************************************************************
_main PROC FAR
mov dx,@data
mov ds,dx
mov dx,offset s$Msg
mov ah,9
int 21h
mov ax,4C00h
int 21h
_main ENDP
;####################################################################################
END _main
notice that the first instructions set the DS register to the data segment, something your program is missing
Quote from: aw27 on May 21, 2018, 01:29:25 AM
Does he know what he wants? ::)
:greenclp:
:lol:
Quote from: felipe on May 21, 2018, 03:59:18 AM
:greenclp:
:lol:
You have a problem in the other thread, perhaps you should concentrate on your projects.
Thanks a lot !
The users of this community are very friendly . Tbh when I asked the question I didn't expected a single answer in 12 hours.
:t
Quote from: jj2007 on May 21, 2018, 04:05:43 AM
Quote from: felipe on May 21, 2018, 03:59:18 AM
:greenclp:
:lol:
You have a problem in the other thread, perhaps you should concentrate on your projects.
What's exactly my problem sir? What are my projects? I don't have any boss here sorry... :eusa_naughty:
cioltealin, if you look for example posted by dedndave you will notice a thing that some persons forgot.
When we declare a string, we use as suffix 0dh,0ah,24h. This means carriage return(0dh), line feed(0ah) and end of string(24h). Windows and linux uses the same EOS (default is 00h) while ms-dos not, it uses a dollar sign ($ == 24h). By default linux use only LF while windows and ms-dos uses CRLF as new line sign.
cioltealin you can try to run your programs with dosbox, maybe will work... :idea:
Don't know if anybody think i was laughing from you, but i was not. I was laughing on the comment from aw27 about your teacher...Just to clarify a little bit and trying to avoid misunderstandings... :redface: