Hey guys, forgive me for this beginner's question but I haven't had any luck in figuring it out. That, and I also am horribly new to all of this.

The first line in my code segment doesn't affect my program in any shape or form. If I put mov something, it does nothing. If I put add something, nothing happens as well.

I guess this is a common error, but I can't figure it out.

Here is my code:


title  Problem 2 (Problem2.asm)
;This program will evaluate the expression a - b / (k + d)
;The program actually gave me an error when I used c as a label for defining one of the variables...I don't know why,
;but in order to get it to work I changed c to k

.model small ;Identifies type of memory model to use

.stack 100h  ;Identifies size of stack segment, can be arbitrary pretty much

.data ;Contains all variables for program ;must all variables be done here?

.code ;Contains all code from program

_main proc

;OVERALL ASSUMPTIONS
;  Besides changing the assuming different bit sizes, there have been certain assumptions made in my code, that
;  would have to be handled differently depending on the case.

; 1. I am assuming that the integers are unsigned. If they are signed of course, the particular numbers given have
;   different representations and I would have to use different functions as well, like imul and idiv.
; 2. I am assuming that (k + d) will not result in an overflow. If it does, then the summation will clearly be wrong.
; 3. I am assuming that either the integer b will be divisible by (k + d), or that the user does not care about
;   the remainder. If it is not, then there will be a divide overflow and the overflow will be in the dx register.


;BIT ASSUMPTION
; Here I will assume that the integers are 16 bits as well.

;allocating memory for variables, will initialize them to ? since I have
;no idea as to what values they will have. Values would be put instead of ?
;for literal expressions.

;16 Bit Assumption

;a - b / (k + d)

a dw 13
b dw 20
k dw 3
d dw 7
Bit16_Result dw ?

mov ax, 3 ;*********************Assembler doesn't even recognize!


Then I keep doing stuff and it recognizes everything. The reason I know that it ignores the line is from using the debugger and noticing that it never even 'reads' that line.

Any help would be greatly appreciate. Thanks guys.

Oh, and awesome forum.  8)
Posted on 2007-05-30 18:57:24 by WinterMute
.data ;Contains all variables for program ;must all variables be done here?


YES, if you want to be able to modify their content.

If you declare them in the .code section as you did, and you examine with your debugger the code generated, you would see the following hex values:

0D 00 14 00 03 00 07 00 00 00

followed by the hex code for the mov ax, 3 instruction. The computer will then try to execute the code starting from the 0D byte believing that it is the start of an instruction. By the time it reaches the mov ax, 3 instruction bytes, some of it may already have been used and the remainder may have no meaning.

Simply transfer your declaration of variables to the .data section.

Raymond
Posted on 2007-05-30 21:09:02 by Raymond

_main proc
a dw 13
b dw 20
k dw 3
d dw 7
Bit16_Result dw ?

mov ax, 3 ;*********************Assembler doesn't even recognize!

Don't put data in a proc like that - when you call your proc, the cpu will assume that it's code and try and execute it. If you want other procs to see the data, do

_main proc
.data        ;  <<<<<<<------
a dw 13
b dw 20
k dw 3
d dw 7
Bit16_Result dw ?
.code        ;  <<<<<<<------
mov ax, 3

If you only want this proc to see them, use LOCALs.
Posted on 2007-05-30 21:58:40 by sinsi
Wow, absolutely amazing guys...thanks.

That comment was actually a note to myself, glad I left it there. I had started to put everything in the code segment because I remember a couple of programs ago I was having problems between addresses and values, and putting it there fixed it.

Makes total sense now. I can now return to my regularly scheduled bit chaos.
Posted on 2007-05-30 22:52:21 by WinterMute

Note that you can use the segment switches any time you like, the assembler will emit them to the current segment in the order they appeared, automatically grouping them.


.code
blah proc
xor eax,eax
.data
db "This is in the data segment",0
.code
ret
Blah endp

is the same as


.data
db "This is in the data segment",0

.code
blah proc
xor eax,eax
ret
Blah endp



Have a nice day :)
Posted on 2007-05-31 22:36:55 by Homer