muapsein.blogspot.com
TITLE PROG2.asm ;File name of program LF equ 0ah ;ASCII 10 - newline character CR equ 0dh ;ASCII 13 - carriage return character NEWLINE equ CR,LF ;Combine CR and LF for carriage return DOUBLESPC equ NEWLINE,LF ;Combine NEWLINE and LF for double space MAXSTR equ 256d ;Accept up to 256 character string .586 ;Allow for Pentium instrucitons .MODEL FLAT ;Memory model is FLAT (4GB) INCLUDE io32.inc ;Include the 32 bit I/O procedures .STACK 4096h ;4k hex bytes for stack .DATA ;Data segment begins here Intro BYTE NEWLINE,'WELCOME!',NEWLINE,\ 'This program allows any user to enter ',\ 'a binary, decimal, or hexadecimal number. The program ',\ 'will then convert that number to the other two formats ',\ 'and ',NEWLINE,\ 'display the results on the screen.',DOUBLESPC,0 Error1 BYTE DOUBLESPC,'Error: Invalid input.',\ ' Please try again.',DOUBLESPC,0 Error2 BYTE DOUBLESPC,'Error: Input too large.',\ ' Please try again.',DOUBLESPC,0 Menu BYTE NEWLINE,' 1) Enter a Binary Number',\ NEWLINE,' 2) Enter a Decimal Number',\ NEWLINE,' 3) Enter a Hexadecimal Number',\ NEWLINE,' 4) Quit',NEWLINE,NEWLINE,0 Prompt BYTE NEWLINE,'Enter your choice --> ',0 BPrompt BYTE NEWLINE,NEWLINE,'Enter a binary number ',\ '(less than 33 digits) --> ',0 DPrompt BYTE NEWLINE,NEWLINE,'Enter a decimal number ',\ '(less than 4294967295d) --> ',0 HPrompt BYTE NEWLINE,NEWLINE,'Enter a hexadecimal number ',\ '(less than 0FFFFFFFFh) --> ',0 TempChar BYTE ? ;Temporary character storage BinVal DWORD ? ;Will hold final Binary Value DecVal DWORD ? ;Will hold final Decimal Value HexVal DWORD ? ;Will hold final Hex Value String BYTE MAXSTR dup(?) ;Holds max sring size TempString BYTE MAXSTR DUP(0) ;Temporary string storage TempInt DWORD 0h ;Temporary integer storage KeyPress BYTE ? ;Temporary storage TempNum DWORD ? ;Temporary number storage Number DWORD 0h ;Holds number value ;************************** Main Body of Program ***************************** ; Given : Nothing ; Process: Main Body - calls procedures to do the processing ; Return : Nothing ;***************************************************************************** .CODE ;executable section begins here _main: lea esi,Intro ;point to intro string in data call PrintString ;display the string Repeat1:lea esi,Menu ;point to menu string in data call PrintString ;display the string lea esi,Prompt ;point to prompt message call PrintString ;display the string lea esi,tempNum ;point to storage for keypressed call GetChar ; and get the char Check1: cmp tempNum,'1' ;Test if 1 was typed jne Check2 ; no, check for 2 call Binary ;If number equals 1 go to binary jmp Repeat1 ;go to menu Check2: cmp tempNum,'2' ;Test if 2 was typed jne Check3 ; no, check for 3 call Decimal ;If number equals 2 go to Decimal jmp Repeat1 ;go to menu Check3: cmp tempNum,'3' ;Test if 3 was typed jne Check4 ; no, check for 4 call Hexadecimal ;If number equals 3 go to hexadecimal jmp Repeat1 ;go to menu Check4: cmp tempNum,'4' ;Test if 4 was typed je EndProgram ; yes, end the program call MenuError ;go to error message for other inputs Binary: lea esi,BPrompt ;point to bprompt message call PrintString ;display the string call GetNum ;Get user binary number ; call ConvertB ;call convertb for decimal and hex call Repeat1 ;Go to Menu options Decimal:lea esi,DPrompt ;point to dprompt message call PrintString ;display the string call GetNum ;Get user decimal number ; call ConvertD ;call convertd for binary and hex call Repeat1 ;Go to Menu options Hexadecimal: lea esi,HPrompt ;point to hprompt call PrintString ;display the string call GetNum ;Get user Hex number ; call ConvertH ;call converth for binary and decimal call Repeat1 ;Go to Menu options MenuError: lea esi,Error1 ;point to error1 message call PrintString ;display the string call Repeat1 ;loops back to start of program EndProgram: INVOKE ExitProcess,0 ;Exit program with return code 0 ;**************** Procedure to ??????????????????????????? ******************** ; Given : ; Process : ; : ; Return : ;****************************************************************************** MyProc PROC NEAR32 pushad ;Save the contents of all registers pushfd ; popfd ;Restore the registers popad ; ret ;Return to Calling procedure MyProc ENDP ;******************* Near procedure to print a string ************************* ; This procedure uses a WHILE... loop to print a string of characters ; Given : The Address of the String to print on the STACK ; Process : Print the String by repeated calls to PrintChar procedure ; Return : Nothing ;****************************************************************************** MyPrintString PROC NEAR32 ;Define a NEAR32 procedure pop eax ;Get RETURN address from Stack pop ebx ;Get STRING address from Stack push eax ;Put RETURN address back on Stack While1: mov dl,[ebx] ;Contents of address pointed to by EBX mov TempChar,dl ;Move the character to temporary store cmp TempChar,0 ;While not end of the string je StringEnd ; Jump to StringEnd on char = 0 (null) lea esi,TempChar ;Address of character to print call PutChar ;Go print a character inc ebx ;Increment pointer to next character jmp While1 ;Go to top of the loop StringEnd:ret ;Return to calling procedure MyPrintString ENDP ;Formal end of procedure ;********************** Procedure to Input the Number ************************* ; Given : Nothing ; Process : Accept a string of ASCII digits and convert them to an integer ; Return : Return the integer in EAX register ;****************************************************************************** GetNum PROC NEAR32 ;Define a NEAR32 procedure push ebx ;Save the contents of all registers push ecx ; except for EAX, which will contain push edx ; the integer number that was read lea esi,TempString ;Pointer to temporary string call GetString ; go get the string lea esi,TempString ;Pointer to temporary string lea edi,TempInt ;Pointer to integer storage call Ascii2Int ;Convert the string to integer mov eax,TempInt ;Copy the integer to EAX pop edx ;Restore the registers in reverse order pop ecx ; pop ebx ; ret ;Return to Calling procedure GetNum ENDP ;Formal end of procedure Public _main END ;Code segment ends |
TAG :
#Projec
#Assembly
#8086Emulator
#Organisasi Komputer
# Contoh Projek Organisasi Komputer
# Contoh Projek Orkom
Tidak ada komentar:
Posting Komentar