Jump to content

Conver 16-bit assembly codes to 32-bit

- - - - -

  • Please log in to reply
2 replies to this topic

#1
jsflrk

jsflrk

    Newbie

  • Members
  • Pip
  • 1 posts
This program below is in 16-bit mode. I find it difficult to convert this into 32-bit in MASM32 source code. Can anyone out there help me.

.MODEL SMALL
 .STACK 100H

 .DATA 
    STR1  DB  'Enter the First character : $'
    STR2  DB  'Enter the Second character : $'
    STR3  DB  ' is first$'
Mistake   DB  13,10,"Only letter is accepted",13,10,'$'

 .CODE
   MAIN PROC
     MOV AX, @DATA                ; initialize DS
     MOV DS, AX

@@:
     MOV DX,offset STR1           ; load and print STR1
     MOV AH, 9
     INT 21H

     CALL GetLetter
     JC   @B

     MOV BL, AL                   ; save the input character into BL

     MOV AH, 2                    ; carriage return
     MOV DL, 0DH
     INT 21H

     MOV DL, 0AH                  ; line feed
     INT 21H

@@:
     MOV DX,offset STR2           ; load and print STR2
     MOV AH, 9
     INT 21H

     CALL GetLetter
     JC   @B

     MOV BH, AL                   ; save the input character into BH

     MOV AH, 2                    ; carriage return
     MOV DL, 0DH
     INT 21H

     MOV DL, 0AH                  ; line feed
     INT 21H

     PUSH BX
     OR  BX,2020h                 ; force lower case
     CMP BL, BH                   ; compare the BL and BH
     POP  BX
     JNBE @ELSE                   ; jump to label @ELSE if BL>BH

     MOV DL, BL                   ; move first character into DL
     JMP @DISPLAY                 ; jump to label @DISPLAY

     @ELSE:                       ; jump label
       MOV DL, BH                 ; move second character into DL

     @DISPLAY:                    ; jump label
       MOV AH, 2                  ; print the character
       INT 21H

     MOV DX,offset STR3           ; load and print STR3
     MOV AH, 9
     INT 21H

     MOV AH, 4CH                  ; return control to DOS
     INT 21H
   MAIN ENDP

GetLetter PROC NEAR

     MOV AH, 1                    ; read a character
     INT 21H

     CMP AL,41h                   ;'A'
     JB  ErrorMsg

     CMP AL,5Ah                   ;'Z'
     JBE Done

     CMP AL,61h                   ;'a'
     JB  ErrorMsg

     CMP AL,7Ah                   ;'z'
     JA  ErrorMsg

Done:
     CLC
     RET

ErrorMsg:
     MOV DX,offset Mistake
     MOV AH, 9
     INT 21H
     STC
     RET

GetLetter ENDP

 END MAIN

Edited by Alexander, 28 January 2011 - 11:14 PM.
bb [code] tags


#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,251 posts
  • Location:C:\Countries\US
What do you have so far?

#3
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
It looks like you will have to learn the Windows API and how to call Windows API functions in MASM.
Latinamne loqueris?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users