The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: flicka on June 21, 2005, 12:22:35 AM

Title: New To masm and Assembly Language - Need Help
Post by: flicka on June 21, 2005, 12:22:35 AM
Hi everyone.

I'm actually just started taking a class in assembly language I have read the text book chapters and I have no idea how to create a program with masm. :green I want to LEARN and understand this so I can go through with class, homework and the exam.

I have MASM32 editor and checked out their demo programs. They are different from what I see in my class book.
This is the first exercise I tried to do following the example from my text book the present the programs as follow:

TITLE          A05ASM1             (EXE)   Program to move and multiply
CODESEG   SEGMENT   PARA 'code'
ASSUME   CS : codeseg, DS : codeseg, SS : codeseg, ES : codeseg
   ORG      100H      ; Start at end of PSP
BEGIN:   JMP      MAIN      ; Jump past data
;------------------------------------------------------------------------------------------------------
MAIN      PROC      NEAR
      MOV      AX, 40H   ; move 40H to AX
      SHL      AL, 1   ; shift A1 1 bit
      MOV      BL,1AH   ; move 1AH to BL
      MVL      BL   ; multiply AL by BL
      MOV      AX, 4C00H   ; end of procedure   

MAIN      ENDP
      END      MAIN

If I do this in MASM it's not working. I'm sure I'm missing a bunch of things.
If anyone can explain to me how a program in Masm should look I can then try to do this correctly. If I can only understand how to write and create 1 program.
PLEASE Don't give me the program done, teach me and explain to me how to get this done on my own...

Thanks for helping me get started with Assembly language.
Title: Re: New To masm and Assembly Language - Need Help
Post by: hutch-- on June 21, 2005, 12:49:27 AM
Hi Flicka,

The code you posted is 16 bit DOS code and it will not build in the MASM32 editor. What you need is the 16 bit Microsoft linker which you can get from the forum web site and you can use the version of ML.EXE that comes with MASM32 and between them you can build successful 16 bit DOS code.

We have a dedicated forum for 16 bit code and many of our members have a lot of experience with this old style code but when you are doing your course work, you must be willing to do your own work before others will help you.
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 21, 2005, 01:02:43 AM
Hi Hutch!

Not a problem on doing my own work, That's actually what I want to be able to do. :U
I just want to understand what I should be doing and which tools I should be using  :U
I'm surprised about what you're saying, but trust me I don't doubt you one second, because my professor had said if we had it we could use Borland turbo debugger win32. So i automatically thaught we were doing 32.

Ok so I can download the 16 bit Microsoft linker and I should be able to do it.. I'll try that right away. I would have spent a week desperately trying to get this to work with MASM32 :lol

Thanks so much Hutch
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 21, 2005, 01:58:12 AM
Thanks Hutch for moving this to the right place!

Ok I have masm32 and I downloaded the linker for 16 bit but now don't how to get these working to write a program with them :eek :red

I really need help to understand how to get the software to work for 16-bit....
Title: Re: New To masm and Assembly Language - Need Help
Post by: Mark Jones on June 21, 2005, 02:26:12 AM
Hi Flicka, here are a few hints.

1. Put X:\MASM32\BIN in your path if possible.
2. Open a command/console/dos prompt and type ML /?
3. Type LINK16 /? (or whatever you named the 16-bit linker executable.)
4. Study the makeit.bat file in the EXAMPLE9\SMALLWIN folder. It is for 32-bit code but shows the basic compilation process.
5. Experiment. :)
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 21, 2005, 02:35:49 AM
Ok Marc,
I'm going to try to figure this out with your hints  :U
I'll let you know how it goes.

Thanks.
Title: Re: New To masm and Assembly Language - Need Help
Post by: hutch-- on June 21, 2005, 02:22:55 PM
OK,

Here is a bare COM template with a batch file to build it. You must name the old 16 bit DOS linker to "link16.exe" and place it in the BIN directory of MASM32. Unzip this file into a directory on the SAME partition as you have MASM32 installed and run MAKE16.BAT to build the COM file.

The batch file has the minimum ML and linker commands to build a com file so you should have a look at it to see what the options are.

The file does a crude clear screen by changing the video mode.

Just to be a bit cheeky, here is how to write the same COM file in HEX.


; ---------------
; com file in HEX
; ---------------

:B4 00          ; mov ah, 00h
:B0 02          ; mov al, 2
:CD 10          ; int 10h
:B8 4C 00       ; mov ax, 004Ch
:CD 21          ; int 21h

; ---------------------------------------------------------------------------
; Select "Save HEX as Binary" option on the File menu to create this COM file
; ---------------------------------------------------------------------------

[attachment deleted by admin]
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 21, 2005, 11:19:44 PM
Hi!

Thanks Hutch!  :U
I just got home from work so I'll try this out tonight and I'll let you know as soon as I get this working and I understand everything  :green2
I do have another question for any of you: Do I have to creat a batch file for each program I create?

Thanks again to all of you. I think with the info I got from you I'll get the hang of this.
Title: Re: New To masm and Assembly Language - Need Help
Post by: hutch-- on June 22, 2005, 03:58:20 AM
If you are doing enough 16 bit code, its easy enough to create a general purpose batch file for each build type, COM, EXE etc ... and the different memory models for the EXE files but in the short term, get used to creating them for each project as you will get good at the assembler and linker options.
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 23, 2005, 12:41:03 AM
Thanks! I think I've got MASM running now...

I do have another question; One of the exercises I have in my textbook asks us to use debug.
Could anyone explain to me how it works? what are the commands I nee to use? The textbook seems to assume we know Debug, but I don't  :red

Any information will be really appreciated.

Thanks!
Title: Re: New To masm and Assembly Language - Need Help
Post by: hutch-- on June 23, 2005, 01:03:19 AM
You actually need a debugger to do this. Ancient MASM came with Codeview but I doubt it will work on a modern box. Its not hard to find 32 bit debuggers but they probably will not work on 16 bit code.

Maybe one of the members can suggest what to use here as I admit I am years out of date writing 16 bit code.
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 23, 2005, 01:09:59 AM
hutch  :toothy
I feel like we're learning some ancient dinausaur  :wink
It's very interesting to learn something new but I'll admit hard...
Thanks.
Title: Re: New To masm and Assembly Language - Need Help
Post by: MichaelW on June 23, 2005, 02:10:43 AM
The attachment is a DEBUG tutorial.



[attachment deleted by admin]
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 23, 2005, 02:15:41 AM
Thanks so much Michael  :U

I'll have a long night tonight working on ASM, MASM, TASM and Debug :wink

I have done a program when I run I get an .exe file but there is nothing, well just the DOS black screen. Would you guys be kind enough to check my program? I would think that I shoud obtain something like a number or a code?

Title test1 program (test1.exe) Move and multiply operations
;--------------------------------------------------------------
STACKSG    SEGMENT PARA STACK 'Stack'
   DW    32    DUP(0)
STACKSG ENDS
;--------------------------------------------------------------
DATASG      SEGMENT   PARA 'Data'
   FLDD   DW   40
   FLDE    DW   1AH
   FLDF    DW    ?
DATASG ENDS
;--------------------------------------------------------------
CODESG    SEGMENT    PARA   'Code'
MAIN    PROC      FAR
   ASSUME SS:STACKSG,DS:DATASG,CS:CODESG
   MOV AX,DATASG             ;Set address of data
   MOV DS,AX             ; segment in DS
   MOV AX,FLDD             ;Move 40H to AX
   SHL AX,1                             ;Shift AL 1 bit left
   MOV BL, 1AH             ;Move immediate value 1AH to BL
   MUL BL                                                                      ; Multiply AL by BL
   MOV AX,4C00H            ;End processing
   INT 21H
MAIN    ENDP               ;End of procedure
CODESG ENDS               ;End of segment
END    MAIN               ;End of program

Thanks Guys
Title: Re: New To masm and Assembly Language - Need Help
Post by: MichaelW on June 23, 2005, 03:01:31 AM
The only error I see is that FLDD is initialized to 40d instead of 40h as implied in one of the comments. You are getting a blank screen because your code is not generating any output. To display the product of the multiply operation you will need to convert it to an ASCII string and then display the string.

Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 23, 2005, 03:38:01 AM
So If I follow you and I get this right I should add H behind 40.

Thanks Michael :thumbu
Title: Re: New To masm and Assembly Language - Need Help
Post by: MichaelW on June 23, 2005, 03:54:42 AM
Either that or remove the H from the comment.

Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 23, 2005, 04:07:55 AM
Thanks Michael.
It's supposed to be move hex 40 to AX, so if I'm not mistaken I should add the H in the program?

We haven't gone over the strings yet. So with the program just like that it is normal to get a black screen for the .exe?
It's starting to make a little more sens  :wink

Thanks again Michael, you're a great help.
Title: Re: New To masm and Assembly Language - Need Help
Post by: hutch-- on June 23, 2005, 04:11:08 AM
 :bg

> I feel like we're learning some ancient dinausaur.

16 bit assembler IS an ancient dinosaur but look at it on the bright side, if you learn to suffer 16 bit assembler and get it up going, segments and all, 32 bit assembler is a joy in comparison with more instructions and a LOT faster. 64 bit is shaping up OK at the moment as well and will have a lot of promise if its developed right.
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 23, 2005, 04:16:54 AM
 :toothy :green :toothy
Hutch that's one of the reasons to suffer : Be able to have fun with 32 bit later on!!
We'll never stop learning  :wink
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 23, 2005, 11:21:59 PM
Hi Guys!

Okay I have a new question for you. On a exercise It asks that I ADD a data segment to the previous program (the one I had posted)
with the following requirements:
* Define 1-byte item (DB) named ITEMA containing hex 40 and another named ITEMB containing hex 1A.
* Define a 2-byte item (DW) named ITEMC with no constant
* Move the content of ITEMA to AL with no constant.
* Multiply AL by ITEMB
* Move the product in AX to ITEMC

Should I write the program like this:
Title test3 program (test3.exe) Move and multiply operations

;--------------------------------------------------------------
STACKSG SEGMENT PARA STACK 'Stack'
DW 32 DUP(0)
STACKSG ENDS
;--------------------------------------------------------------
DATASG SEGMENT PARA 'Data'
ITEMA DB 40H
ITEMB DB 1AH
ITEMC DW ?
DATASG ENDS
;--------------------------------------------------------------
CODESG SEGMENT PARA 'Code'
MAIN PROC FAR
ASSUME SS:STACKSG,DS:DATASG,CS:CODESG
MOV AX,DATASG     ; Set address of data
MOV DS,AX     ; segment in DS
MOV AL,ITEMA     ; Move 40H to AX
SHL AL,1     ; Shift AL 1 bit left
MOV BL, 1AH     ; Move immediate value 1AH to BL
MUL ITEMB                                                    ; Multiply AL by BL
                MOV AX, ITEMC                                             ; Move the product in AX to ITEMC
MOV AX,4C00H     ; End processing
INT 21H
MAIN ENDP     ; End of procedure
CODESG ENDS     ; End of segment
END MAIN     ; End of program

or should I write it like this:
Title test1 program (test1.exe) Move and multiply operations
;--------------------------------------------------------------
STACKSG SEGMENT PARA STACK 'Stack'
DW 32 DUP(0)
STACKSG ENDS
;--------------------------------------------------------------
DATASG SEGMENT PARA 'Data'
FLDD DW 40H
FLDE DW 1AH
FLDF DW ?
                ITEMA       DB            40H
                ITEMB       DB            1AH
                ITEMC       DW            ?
DATASG ENDS
;--------------------------------------------------------------
CODESG SEGMENT PARA 'Code'
MAIN PROC FAR
ASSUME SS:STACKSG,DS:DATASG,CS:CODESG
MOV AX,DATASG     ; Set address of data
MOV DS,AX     ; segment in DS
MOV AL,ITEMA     ; Move 40H to AX
SHL AL,1     ; Shift AL 1 bit left
MOV BL, 1AH     ; Move immediate value 1AH to BL
MUL ITEMB                                                    ; Multiply AL by BL
                MOV AX, ITEMC                                             ; Move the product in AX to ITEMC
MOV AX,4C00H     ; End processing
INT 21H
MAIN ENDP     ; End of procedure
CODESG ENDS     ; End of segment
END MAIN     ; End of program


Thanks guys for you help.

I just added the "code" tags in square brackets so that the formatting is retained. Makes your code a lot easier to read.
Title: Re: New To masm and Assembly Language - Need Help
Post by: MichaelW on June 24, 2005, 03:42:30 AM
The three old variables serve no purpose here because the code does not refer to them. The comment on the MOV AL, ITEMA instruction is not correct. The code is shifting AL, an operation that is not listed in the requirements and which will affect the results. To move the product into ITEMC, AX must be the source and ITEMC the destination.
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 24, 2005, 03:56:22 AM
Hutch, sorry :red

So Michael, If I get this right: The program should be:

;--------------------------------------------------------------
STACKSG    SEGMENT PARA STACK 'Stack'
   DW    32    DUP(0)
STACKSG ENDS
;--------------------------------------------------------------
DATASG      SEGMENT   PARA 'Data'
   ITEMA   DB   40H
   ITEMB    DB   1AH
   ITEMC    DW   ?
DATASG ENDS
;--------------------------------------------------------------
CODESG    SEGMENT    PARA   'Code'
MAIN    PROC      FAR
   ASSUME SS:STACKSG,DS:DATASG,CS:CODESG
   MOV AX,DATASG             ; Set address of data
   MOV DS,AX             ; segment in DS
   MOV AX,ITEMA             ; Move 40H to AX
                SHL AL                                                          ; Shift AL
   MOV BL, 1AH              ; Move immediate value 1AH to BL
   MUL ITEMB                                                    ; Multiply AL by BL
                MOV ITEMC,AX                                              ; Move the product in AX to ITEMC
   MOV AX,4C00H             ; End processing
   INT 21H
MAIN    ENDP                ; End of procedure
CODESG ENDS                ; End of segment
END    MAIN                ; End of program

Would this be correct?
Title: Re: New To masm and Assembly Language - Need Help
Post by: MichaelW on June 24, 2005, 04:20:26 AM
QuoteMove the content of ITEMA to AL...

The instruction was correct in your previous post, only the comment was wrong. Now the instruction matches the comment, but neither match the requirement.


Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 24, 2005, 04:38:03 AM
Ok Michael Got it!
I'll make the change back in the program and change the comment.
Otherwise it seem Ok to you?
Title: Re: New To masm and Assembly Language - Need Help
Post by: MichaelW on June 24, 2005, 06:52:05 AM
Yes. It looks OK, it assembles and links OK, and it does not blow up when I run it.

Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on June 24, 2005, 12:57:55 PM
Thanks Micheal  :U

It's good news if it doesn't blow up when you run it...  :green :green
At least it means that I'm starting to get an understanding of what I'm doing thanks to you  :wink

I won't be around this week-end since I have to help out at a town's special event all week-end, but I'll check back in Monday.
Have a great WE.
Title: Re: New To masm and Assembly Language - Need Help
Post by: flicka on July 17, 2005, 09:48:32 PM
Hi Guys!

I'm bringing a new program of my "creation" to your attention to see If I'm understanding all this correctly. This one is a little more trickier for me, but I tried.
The exercice is: Write a program that uses INT 2lH function 0AH to accept data from the keyboard and INT 10H function 13H to display the characters. Clear the screen, set screen colors to green on gray, set the border color to blue, and initialize the cursor to row 0, column 2. Use a variety of colors, reverse video, or beeping. Accept data from the keyboard beginning at the current position of the cursor. Then set the cursor to column 78, and display the entered data in reverse (backwards) sequence, from right to left. Increment for the next row. Display entered data down the screen until reaching row 24, and then begin scrolling. The program is to accept any number of entries and ends when the user presses <Enter> with no data. Write the program with a short main logic routine and a series of called subroutines.  

Here is what I did:
Quote
                    .MODEL SMALL
                    .STACK 64
                    .DATA
   CHAR_CTR   DB 00
   COL            DB 24
   ROW          DB 24
   MODE         DB ?       
;--------------------------------------------------------------
              .CODE            ; Define code segment
   A10MAIN    PROC NEAR
             MOV AX,@data                
             MOV DS,AX                
             MOV ES,AX
             CALL Q10CLEAR
             CALL B10SCREEN
             CALL C10INPUT
             CALL D10CURSOR
             CALL E10DISPLY
             CALL F10SCROLL
             MOV AX,4C00H
             INT 21H
   A10MAIN    ENDP
; Clear Screen and Set Attributes                             
;--------------------------------------------------------------
   B10SCREEN  PROC NEAR
              PUSHA
              MOV AX,0600H                
             MOV BH,82H             
             MOV CX,000H       
            MOV DX,184FH            
             INT 10H
   B10SCREEN  ENDP               ;End of procedure
; Display prompt and accept input:                             
;--------------------------------------------------------------
   C10INPUT   PROC NEAR
              PUSH AX
              PUSH DX
              MOV AH,09H                
             INT 21H       
              MOV AH,0AH                
             INT 21H
             POP DX
             POP AX
             RET
   C10INPUT   ENDP               ;End of procedure
; Set cursor to row and column:                             
;--------------------------------------------------------------
   D10CURSOR  PROC NEAR
              PUSHA
              MOV AX,02H                
             MOV BH,00             
             MOV DH,ROW       
            MOV DL,78            
             INT 10H
             POPA
             RET
   D10CURSOR  ENDP               ;End of procedure
; Display Name backwards:                             
;--------------------------------------------------------------
   E10DISPLY  PROC NEAR
              MOV AH,0AH                
             MOV AL,00             
             MOV DH,CHAR_CTR   
             MOV BH,00      
            MOV CX,01            
             INT 10H
             POPA
             RET
   E10DISPLY  ENDP               ;End of procedure
; Scroll Screen:                             
;--------------------------------------------------------------
   F10SCROLL  PROC NEAR
              PUSHA
              MOV AH,06H                
             MOV BH,29H   
             MOV CX,0000      
            MOV DX,184FH            
             INT 10H
             POPA
             RET
   F10SCROLL  ENDP               ;End of procedure
   
              END    A10MAIN         ;End of program       

Please review it and let me know if it's ok or not.
Thanks guys.