News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Need some help

Started by RMY-Jeddy, August 25, 2012, 05:10:17 PM

Previous topic - Next topic

RMY-Jeddy

Hey mates, I need some help with this program, as you can see I'm really not that good at it.

Create labex824.asm that contains the following procedures:

–         Contains the procedure named CLR that clears all the content of registers ax to dx

–         Procedure RD reads the contents of memory locations M1 and M2 and store their contents to AX and BX respectively, M1 = 234A, M2 = E456

–         Procedure AD that adds the contents of AX and BX then store the answer to M3

–         Procedure SB that subtracts the contents of AX from BX and stores the answer to M4

–         Procedure ML that multiplies the content of AX to BX and store the high and low procedures to M5 and M6 respectively

–         Procedure DV that divides BX by 5 then add the quotient to AX then store the final answer to M7

–         Procedure EX that negates AX then add it to BX after BX was incremented three times

TouEnMasm


That will be better if you can post your code.
Copy paste in a post or made a zip and attach it
Fa is a musical note to play with CL

RMY-Jeddy

Page 60,132
TITLE LABEXGALSOTE.ASM

.MODEL   SMALL
.STACK 64
.DATA
   M1   DW   234A
   M2   DW   0E456
   M3   DW   ?
   M4   DW   ?
   M5   DW   ?
   M6   DW   ?
   M7   DW   ?

.CODE
   MAIN PROF FAR
   CALL CLR
   CALL RD
   CALL AD
   CALL SB
   CALL ML
   MOV AX, 4C00H
   INT 21
   MAIN   ENDP
   
   CLR PROF FAR
   AND AX,0
   AND BX, 0
   RET
   OD ENDP

   RD PROF FAR
   MOV AX, M1
   MOV BX, M2
   RET
   RD ENDP

   AD PROF FAR
   ADD AX, BX
   MOV M3, AX
   RET
   AD ENDP

   SB PROF FAR
   SUB AX, BX
   MOV M4, AX
   RET
   SB ENDP

   ML PROF FAR
   MUL AX, BX
   MOV M5, AX
   RET
   ML ENDP

   
   END MAIN

Having problems with the instructions from multiplication onwards, any help will be appreciated

MichaelW

Your source contains multiple errors that ML is catching and reporting. ML stops the assembly process when it encounters a fatal error, so to see all of the error messages you must fix each of the fatal errors and then repeat the assembly process. Here is the original source with all of the error messages:

Page 60,132
TITLE LABEXGALSOTE.ASM

.MODEL   SMALL
.STACK 64
.DATA
   M1   DW   234A   ;rmy_err.asm(7) : error A2048: nondigit in number
   M2   DW   0E456  ;rmy_err.asm(8) : error A2048: nondigit in number
   M3   DW   ?
   M4   DW   ?
   M5   DW   ?
   M6   DW   ?
   M7   DW   ?

.CODE
   MAIN PROF FAR    ;rmy_err.asm(16) : error A2008: syntax error : PROF
   CALL CLR
   CALL RD
   CALL AD
   CALL SB
   CALL ML
   MOV AX, 4C00H
   INT 21
   MAIN   ENDP      ;rmy_err.asm(24) : fatal error A1010: unmatched block nesting : MAIN

   CLR PROF FAR     ;rmy_err.asm(26) : error A2008: syntax error : PROF
   AND AX,0
   AND BX, 0
   RET
   OD  ENDP         ;rmy_err.asm(30) : fatal error A1010: unmatched block nesting : OD

   RD PROF FAR      ;rmy_err.asm(32) : error A2008: syntax error : PROF
   MOV AX, M1
   MOV BX, M2
   RET
   RD ENDP          ;rmy_err.asm(36) : fatal error A1010: unmatched block nesting : RD

   AD PROF FAR      ;rmy_err.asm(38) : error A2008: syntax error : PROF
   ADD AX, BX
   MOV M3, AX
   RET
   AD ENDP          ;rmy_err.asm(42) : fatal error A1010: unmatched block nesting : AD

   SB PROF FAR      ;rmy_err.asm(44) : error A2008: syntax error : PROF
   SUB AX, BX
   MOV M4, AX
   RET
   SB ENDP          ;rmy_err.asm(48) : fatal error A1010: unmatched block nesting : SB

   ML PROF FAR      ;rmy_err.asm(50) : error A2008: syntax error : PROF
   MUL AX, BX       ;rmy_err.asm(51) : error A2008: syntax error : ,
   MOV M5, AX
   RET
   ML ENDP          ;rmy_err.asm(54) : fatal error A1010: unmatched block nesting : ML


   END MAIN


Except for the MUL instruction the problems and the fixes should be obvious. For MUL see the instruction documentation.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

you did pretty well, actually

the biggest problem i see is the word "PROF" should be "PROC" (short for "procedure")
and - no need for these to be FAR procedures - NEAR should be fine

the CLR routine only clears AX and BX - missing CX and DX
we generally use XOR or SUB to zero registers
        xor     ax,ax

the SB procedure...
the instructions say "subtract AX from BX" - you have the source and destination reversed
        sub     bx,ax
        mov     M4,bx


the MUL instruction implies AX as one of the source registers
the instructions say "store the high and low procedures to M5 and M6 respectively"
misuse of the word "procedures", but...
        mul     bx
        mov     M5,dx
        mov     M6,ax


the DV procedure is a bit tricky because of register usage   :biggrin:
"divide BX by 5 then add the quotient to AX then store the final answer to M7"
DIV divides the 32-bit value in DX:AX by a word
the quotient will be in AX and the remainder (modulus) will be in DX
        mov     cx,5
        xchg    ax,bx
        xor     dx,dx
        div     cx
        add     ax,bx
        mov     M7,ax


"Procedure EX that negates AX then add it to BX after BX was incremented three times"
        neg     ax
        inc     bx
        inc     bx
        inc     bx
        add     bx,ax

MichaelTripi68

I am new to ASM so you may see may asking alot of questions about posts and code.  I was wondering what is it that you are trying to here?

dedndave

it's just a "trivial" program
not really meant to DO anything - lol
just a learning exercise

FORTRANS

Hi,

   Consider this an exercise to write, assemble, and then run
the program in DEBUG to see what happens as each instruction
is executed.  You would use the Trace or Procede commands
in DEBUG to see how the contents of the registers change as
each instruction is executed.

Regards,

Steve N.

RMY-Jeddy

Thanks for the help mates, I've already figured it out  :t