New To masm and Assembly Language - Need Help

Started by flicka, June 21, 2005, 12:22:35 AM

Previous topic - Next topic

flicka

So If I follow you and I get this right I should add H behind 40.

Thanks Michael :thumbu

MichaelW

Either that or remove the H from the comment.

eschew obfuscation

flicka

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.

hutch--

 :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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

flicka

 :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

flicka

#20
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.

MichaelW

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.
eschew obfuscation

flicka

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?

MichaelW

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.


eschew obfuscation

flicka

Ok Michael Got it!
I'll make the change back in the program and change the comment.
Otherwise it seem Ok to you?

MichaelW

Yes. It looks OK, it assembles and links OK, and it does not blow up when I run it.

eschew obfuscation

flicka

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.

flicka

#27
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.