mReadInt_mWriteInt_Macro (Chapter 10, Pr 5 and Pr 6, Modified).TXT

mReadInt_mWriteInt_Macro (Chapter 10, Pr 5 and Pr 6, Modified)

Pr 5: Create a macro named mReadInt that reads a 16- or 32-bit signed integer from standard input and returns the value in an argument. mReadInt MACRO intVal Use conditional operators to allow the macro to adapt to the size of the desired result. Write a program that calls the macro, passing it operands of various sizes, either signed or unsigned. If the operand has an unexpected size, should display an error message during assembling, e.g., when you test ; Pass different sizes of arguments ... mReadInt AL ; test the macro's error message the build issues error during assembling because the BYTE AL has an unexpected size 1MASM : error : ************************************************************************ 1MASM : error : Argument AL passed to mReadInt must be either 16 or 32 bits. 1MASM : error : AL must be of 16 or 32-bit data type. 1MASM : error : ************************************************************************ As see above, "Argument AL" is mentioned and no code assembled for AL. If mReadInt bVal as a BYTE, the error message should be "error : Argument bVal passed...". In a valid test, you should be able to pass an argument to mReadInt and get it back to verify like this: mWrite "Enter a 32-bit integer: " mReadInt dVal mWriteInt dVal mWrite "Enter a 16-bit integer: " mReadInt BX mWriteInt BX Here is an output of examples to use DWORD dVal and BX as arguments: Enter a 32-bit integer: 1234000111 dVal = +1234000111 Enter a 16-bit integer: -32000 BX = -32000 Pr 6: Create a macro named mWriteInt that writes a signed integer to standard output by calling WriteInt. The argument passed to the macro can be a positive or negative valued operand. Use conditional operators in the macro so it adapts to the size of the argument. Write a program that demonstrates the macro, passing it arguments of different sizes. You can define bVal SBYTE -2 wVal SWORD -122 dVal DWORD 1234567 qVal QWORD 11 and in code, simply test by invoking mWriteInt six times: mWriteInt bVal mWriteInt wVal mWriteInt dVal mWriteInt AX mWriteInt ebx ; Test the macro's error message mWriteInt qVal But the build issues warning during assembling because the operand qVal has an unexpected size, and then you display an warning message: 1 Assembling [Inputs]... 1MASM : warning : ************************************************************************ 1MASM : warning : Argument qVal passed to mWriteInt must be 8, 16, or 32 bits. 1MASM : warning : ************************************************************************ As see here, "Argument qVal" is indicated and and no code assembled for this qVal. You can check your code either at assembly time and test valid results at run time. The substitution & operator in your macro can make the output like this: bVal = -2 wVal = -122 dVal = +1234567 AX = +13176 ebx = +2130567168 Write three parts into one .ASM file: mReadInt, mWriteInt, and main. Attention to: The Macro parameter intVal can receive either register or memory of any size when being called Compare sizes and assign values between the type-less parameter intVal and the register Accumulator Make push/pop matching in pair in any conditions When test invalid sizes, mReadInt AL and mWriteInt qVal, make sure no code generated in listing Don't use mShow in your homework, but can read it as a good reference
Powered by