Write a microprogram to implement MOV A B in Assembly 67 Wri
Write a microprogram to implement MOV A, B in Assembly...
6.7 Write the microprogram to implement the following move multiple words instruction: MOVA,B which moves N words from memory locations starting at A to those at B. The value of Nis specified in the accumulator. Assume that A and B are represented as 4-bit fields in the 8-bit operand field of the instruction, and indexing and indirecting are not allowed. What is the limitation of this instruction?Solution
We know that the operands of the MOV instruction cannot both be word variables, but we can define a macro to move a word source variable to a word destination variable.
MOVW MACRO WORD1, WORD2
PUSH WORD2
POP WORD1
ENDM
To use a macro in a program, we invoke it.
Syntax:
macro_name a1, a2, a3,…,an
where a1, a2, …, an is a list of actual arguments.
Example: Invoke the macro MOVW to move B to A, where A and B are word variables.
.DATA
A DW ?
B DW ?
.CODE
...
MOVW A, B
Macro expansion - character substitution of actual arguments.
These instructions:
MOVW A, DX
MOVW A+2, B
Insert the following (equivalent) code into a program:
PUSH DX
POP A
PUSH B
POP A+2
Special Invocations
MOVW AX, 1ABCH generates the code
PUSH 1ABCH
POP AX
Pushing an immediate value requires using a processor directive (e.g., .586) before the push instruction will be recognized by the assembler translator.
Restoring Registers
Good programming practice requires that a procedure should restore the registers that it uses, unless they contain output values. The same is true for macros.
Program Listing
.MODEL SMALL
MOVW MACRO WORD1,WORD2
PUSH WORD2
POP WORD1
ENDM
.STACK 100H
.DATA
A DW 1,2
B DW 3
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOVW A,DX
MOVW A+2,B
;dos exit
MOV AH,4C00H
INT 21H
MAIN ENDP
END MAIN
Write a program to initialize a block of memory to the first N integers. Then invoke it in a program to initialize an array to the first 100 integers.
BLOCK MACRO N
K=1
REPT N
DW K ; generates program code
K=K+1
ENDM
ENDM

