flat assembler
Message board for the users of flat assembler.

Index > DOS > Simple Code not running

Author
Thread Post new topic Reply to topic
VG



Joined: 12 May 2005
Posts: 6
VG 13 May 2005, 07:49
The following coding has been given in our Assembly Language course book, but it is not running on FASM ( Windows version). What shall i do.
Thanx.

Code:
; This probram adds two 8-bit words in the memory locations
;called NUM1 and NUM2. The result is stored in the memory location called
; RESULT. If there was a carry from teh addition it will be stored as 0000 
;0001 in the location CARRY.

DATA SEGMENT

NUM1 DB 15h  ;First number is stored here
NUM2 DB 20h  ; Second number stored here
RESULT  DB  ? ; Put sum here 
CARRY DB ?  ; Put any carry here
DATA ENDS
CODE SEGMENT
           ASSUME CS:CODE, DS:DATA
START:    MOV AX, DATA                        ;Initialize data segment
               MOV DS, AX ; register            ; register
               MOV AL, NUM1            ; Get the first number
               ADD AL, NUM2            ; Add it to 2nd number
               MOV RESULT, AL          ; Store the result
               RCL AL, 01                ; Rotate carry into LSB
               AND AL, 00000001B      ; Mask out all but LSB
               MOV CARRY, AL ; Store the carry result
              MOV AX, 4C00H
               INT 21h
CODE ENDS
               END START    
Post 13 May 2005, 07:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20337
Location: In your JS exploiting you and your system
revolution 13 May 2005, 08:21
Code:
; This probram adds two 8-bit words in the memory locations 
;called NUM1 and NUM2. The result is stored in the memory location called 
; RESULT. If there was a carry from teh addition it will be stored as 0000 
;0001 in the location CARRY. 

        org     100h                    ;code starts at offset 100h
        use16                           ;use 16-bit code
        jmp     START

NUM1 DB 15h ;First number is stored here 
NUM2 DB 20h ; Second number stored here 
RESULT DB ? ; Put sum here 
CARRY DB ? ; Put any carry here 

START:
MOV AL, [NUM1] ; Get the first number 
ADD AL, [NUM2] ; Add it to 2nd number 
MOV [RESULT], AL ; Store the result 
RCL AL, 01 ; Rotate carry into LSB 
AND AL, 00000001B ; Mask out all but LSB 
MOV [CARRY], AL ; Store the carry result 
MOV AX, 4C00H 
INT 21h 
    
Post 13 May 2005, 08:21
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 13 May 2005, 08:30
More literal conversion:
Code:
FORMAT MZ

SEGMENT _DATA ; CODE and DATA are reserved words in fasm,
              ; so other have to be used for segment names

NUM1 DB 15h ;First number is stored here
NUM2 DB 20h ; Second number stored here
RESULT DB ? ; Put sum here
CARRY DB ? ; Put any carry here

SEGMENT _CODE

START: MOV AX, _DATA ;Initialize data segment
MOV DS, AX ; register ; register
MOV AL, [NUM1] ; Get the first number
ADD AL, [NUM2] ; Add it to 2nd number
MOV [RESULT], AL ; Store the result
RCL AL, 01 ; Rotate carry into LSB
AND AL, 00000001B ; Mask out all but LSB
MOV [CARRY], AL ; Store the carry result
MOV AX, 4C00H
INT 21h

ENTRY _CODE:START    
Post 13 May 2005, 08:30
View user's profile Send private message Visit poster's website Reply with quote
VG



Joined: 12 May 2005
Posts: 6
VG 13 May 2005, 08:48
Very thanks. But you didnot tell me what is the problem with my code. After all i have to depend on my book, for reference. Are all my code incapable of running on FASM?
Post 13 May 2005, 08:48
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 13 May 2005, 08:54
Your book is for the different dialect of assembly language - that's why the translation was needed. You might try reading the fasm's Programmer's Manual (especially section 1.2) to see what the differencies are.

Also, your code is a DOS program, you should have posted in the DOS forum instead.
Post 13 May 2005, 08:54
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.