National University of Singapore

EE2007 Page | IVLE | NUS Email | NUS Home
subglobal1 link | subglobal1 link | subglobal1 link | subglobal1 link | subglobal1 link | subglobal1 link | subglobal1 link
subglobal2 link | subglobal2 link | subglobal2 link | subglobal2 link | subglobal2 link | subglobal2 link | subglobal2 link
subglobal3 link | subglobal3 link | subglobal3 link | subglobal3 link | subglobal3 link | subglobal3 link | subglobal3 link
subglobal4 link | subglobal4 link | subglobal4 link | subglobal4 link | subglobal4 link | subglobal4 link | subglobal4 link
subglobal5 link | subglobal5 link | subglobal5 link | subglobal5 link | subglobal5 link | subglobal5 link | subglobal5 link
subglobal6 link | subglobal6 link | subglobal6 link | subglobal6 link | subglobal6 link | subglobal6 link | subglobal6 link
subglobal7 link | subglobal7 link | subglobal7 link | subglobal7 link | subglobal7 link | subglobal7 link | subglobal7 link
subglobal8 link | subglobal8 link | subglobal8 link | subglobal8 link | subglobal8 link | subglobal8 link | subglobal8 link
 

EE2007 MicroprocessorsTutorial

> Questions
©2004-2005 Pan Yan, ECE Department, National University of Singapore
Q.1. [Aug-26-2004] When performing operation like cmp or logic operators(XOR, NOT, NEG, OR ,AND), where will be the "value" of the operation stored?

Ans: Well, actually, it depends on each of the instructions. You can look up the description of each of these instructions from any manual.
Usually, the result will again be stored in register AX. As we discussed, the processor works on registers.

Q.2. [Aug-26-2004] How do I do print a "ENTER-KEY" (next line) on the screen? I tried
searching under the ascii table but did not find anything useful.
Ans: Well, you should output two chars in sequence. They are 0x0D and 0x0A. They are "Carriage Return" and "Line Feed". So you may want define your string as:
sMessage DB 'Hello, World!',13,10,'$'
sMessage here is a string. '$' is the end of the string. We can use certain interrupt to output it. You can look up HelpPC for such function.
Q.3. [Aug-26-2004] I have some problems with the help pc. If I want to perform a
certain task(e.g. read user input), how do I go about searching which
interrupt I should use? Or do I have to go through all the functions
and find what I need?
Ans: Well, you can go through directories.
After selecting "Interrupt Services DOS BIOS EMS Mouse" from the main
menu, you can see several directories listed on top of the screen,
say, "BIOS Break Interrupt", "BIOS Clock Services" and so on.
You can go into "BIOS Keyboard Services" for example to search for
keyboard i/o functions. They will be listed.
Use "TAB" key to browse.
Q.4. [Aug-29-2004] It seems that EMU8086 IDE produces error messages when I migrate the exact *.asm file which worked with TASM.
The error messages under status:
WARNING: ASSUME directive not supported (ignored)
Compliation Errors:
NUM DB (?) <-- unable to evaluate expression
CALL CS:USRINPUT <-- FAR CALL CS:USRINPUT not supported yet.
Ans:Well, as the EMU8086 works on a virtual machine, it has certain limitations.
Just ignore the WARNING. It's OK. ASSUME directive is ignored.
for NUM DB (?), I think you can change (?) for any integer number between 0~255. This may be because the assembler in EMU8086 has minor difference with TASM.
for CALL CS:USRINPUT, I guest u can change it for CALL USRINPUT, if you have only one segment for code (I guess it is the case.).
Generally, EMU8086 is an emulator for preliminary study. It helps you easily monitor all the registers and the flow of the program. However, it's very difficult to emulate the whole processor. So the emulator has limitations as not supporting far calls and some DOS interrupts. For example, many of the INT 21H interrupts are not supported either.
Anyway, I suggest you use it to familiarize with the basic ideas of a processor. You can first make use of the sample codes given by the software.
Q.5. [Aug-30-2004] I need to create a procedure which converts Hex numbers representation
within AX into decimal representation in order to output them....

Say for example, A1FFh is stored within the register AX. How do i go
about to construct the decimal representation? I know that it can be
calculated by A * 16^3 + 1 * 16 ^2 + F * 16^1 + F * 16^0
but i'm lost in converting this principle onto assemble. Any clues?

Ans: You can simply divide the register by 10. When you do
calculations, we don't have to worry about the form of the number in
the register. Anyway it's saved in the register in binary form ( as
high / low voltages for each bit). uPs always works on BIN form, but
the assembly language can asscess it in any form.

For example,
MOV AX, 10
MOV AX, 0Ah

These two instructions simply moves DEC and HEX values into AX. They
are the same. You can write in either way. What we have in the
register then is just the number. We can say it's 10 or 0Ah. It's the
same. But if we want to output it, or print it, we have to worry about
the form. If we want to print it in HEX, we have to convert the number
to one HEX digit. If we want to print it in DEC, we have to get the
tens and units digits. Each digit will be converted to one character
and printed.

Maybe you need DIV instruction, to divide the number by 10. The quotien
t and remainder are the tens and units digits. You can then convert these
digits ( in number ) to characters (ASCII CODE) and output them by some
DOS interrupt calls.

Q.6. [Sep-1-2004]I have the following code, with AX as the number I want:
mov AX, result
div 10
why do i get an divide overflow error?
Ans: Well, I guess the problem is that DIV instruction takes a parameter of
a register or memory location. Using DIV 10, you are actually dividing
the number by the value stored at the address 10 in the memory, which
could be zero. You may refer to
http://doc.ddart.net/asm/Microsoft_MASM_Programmers_Guide_v6.1/Chap_04.htm
for more infomation on DIV and MUL instructions.
Possibly you should put 10 into a register and use, say, DIV AL.
Q.7. [Sep-3-2004] I'm not sure what does this line do
tos label word
And is it necessary in HELLO.ASM?

Ans: Well, this defines a label named tos. The meaning of it is "Top Of
Stack". As you see, this label appears at the end of the stack
segment. So it serves as the pointer to the top of the stack, and will
be loaded into SP register later as initiallization.

If you look at the PUSH and POP instructions in a manual, you will
find that pushing something into the stack will cause the pointer SP
be DECREASED. That's why "TOS" is at the end of the stack segment. It
has the highest address.

It is necessary. If you refer to the definition of the INT instruction, you will see the CS:IP pair will be pushed into stack automatically. So you have to prepare SS and SP to be pointing to the top of the stack. That's why SS and SP are initialized right at the start of the program.

Q.8. [Sep-04-2004] if we say MOV BX, AX-are we copying the address of AX into BX, or the data content of AX into BX?

Ans: Registers for our processor does not have an "ADDRESS". So MOVE BX, AX is purely register moving. The content of AX will be moved to BX.

Q.9. [Sep-04-2004] if we sayMOV AX, [BX], do we store the address itself which is 10H*DS+[BX] into AX, or do we store the data residing at 10H*DS+[BX] into AX?

Ans: Here, we are accessing the memory. This will move the content of the address indicated by the content of BX to AX. If you want to move the address, you should use the OFFSET directive. You may read Tut_Supp_3. A detail explaination of OFFSET and SEG directives is included.

What's more, as the registers are 16 bit, we can never store the whole 20-bit physical address ( for example, 10H*DS+[BX] ) into a single register. The seg and offset parts are saved separately, as by using OFFSET and SEG.

MOV itself does the data content moving. But you can move the address by using OFFSET or SEG directives.

Q.10. [Sep-04-2004] can I use MOV MRC 3FCH instead of MRC EQU 3FCH?
the line MOV DX, MCR-am I correct in saying that the address of MCR is stored into DX register?

Ans: No. EQU is a directive that defines a macro. It's not an instruction to move some data into a memory location or register. MRC here is only a symbol defined. Each time the assembler reads MRC in the source code, it will substitute it for 3FCh. It's similar as #define in C.

MCR does not have an address. The instruction is the same as MOV DX, 3FCH The assember will do the substitution for you.

Q.11. When we want to clear DF flag, we use CLD to clear rite. DI and SI are incremented. How do we set the DF flag then?
Ans:Use STD. It is simply SeT Direction flag.
You may refer to:
http://spike.scu.edu.au/~barry/80x86_inst.html#STD
Q.13. What is the difference between TEMP EQU 3 and TEMP DB 1 DUP(3)? Or should it be TEMP DB 1 DUP(33H)?
Ans: TEMP EQU 3 is like a macro in the C language. It only tells the assembler to take TEMP as 3. It is a simple one to one substitution. You can NOT use MOV BX, OFFSET TEMP to retrieve the address of the symbol.

TEMP DB 1 DUP (33H) will allocate one byte of memory space and store 33h in that location. You CAN use MOV BX, OFFSET TEMP to get the address.

Q.14. When do we use AX instead of AL or AH? Is it only when we are storing data that are 2 bytes in size? If we know the data is 1 byte but we still use AX, where will the data be stored in, AH or AL?
Ans:As you know, AL and AH are parts of AX. The processor will mostly process on AX, that is, on a 16-bit basis. For example, PUSH AX will push the 16-bit data into the stack together. However, you can move byte data to only AL or AH. If you only have 1 byte data and want to use AX, you have to load that byte into AL and clear AH.
Q.15. Let's say we have a value in [DI], I suppose the value should be in hexidecimal. I would like to print the value stored in [DI], but I am not sure how to.
I know that there is a function called "AAA" which we have to use addition, so I try
add [DI], 0
AAA
mov AH, 02h
mov DL, [DI]
int 21h

but I got a diamond shape instead. Is my method correct?
Ans:AAA is an instruction that I never used. :)
But I am sure you can not use it that way. It is actually used to "adjust" the result got from a binary addition with BCD operands back into BCD format. That is, if you have 79 and 01 in BCD form, say, 01111001 and 00000001, you can use ADD to do the addition. What you get then is a binary addition result, 01111010. This is not the BCD code of the correct result 80. What you want should be 10000000. AAA is used here to adjust 01111010 to 10000000. In short, to use AAA, you must have the operands already in BCD format.
To display the content of a register, you might like to refer to the sample subroutine you may get from the lecturer. There is no easy way of doing it. Actually, to display a 16-bit data in the register, you must use DIV to repeatedly divide by 16 (if you want to display it in HEX form. To display in DEC form, you should divide by 10). Then you can collect the remainders and display the remainders digit by digit. To display each digit, you must convert the remainder data into ASCII code. For HEX form, you must treat 0~9 and 10~15 separately. For DEC form, it's much easier. You simply add the data with the char '0'.
Q.16. I found this line in the text book : "The bus interface unit contains the circuit for physical address calculations and a predecoding instruction byte queue(6 bytes long )". What exactly is this "predecoding instruction byte queue" ? What does it do?
Ans: That is a pipelined feature. The BIU will automatically fetch instructions from the memory as long as an internal queue of instruction is not full. This prefetch operation could be carried out at the same time when the EU is executing some previously fetched instructions. Thus, time is saved. You may refer to http://www.ganssle.com/articles/aprefetc.htm
Read the section below "Prefetchers".

Q.17. I have a question regarding Tutorial 2 question 3.
ˇ°Show how the double word 12345678h will be stored in memory starting at address A001.ˇ±
The answer given is
A001 78
A002 56
A003 34
A004 12
My question is that I thought that the system is supposed to process 16 bit a time and should read the first 16 bit, therefore my answer is
A001 34
A002 12
A003 78
A004 56
Why am I wrong? Does it mean that the system would always process the whole word regardless of its length? The memory location would always start from LSB down to MSB regardless whether it is 16bit, 32 bit, 64 bit or 128 bit?

Ans: This is a good question. Actually, even though the 8086/8088 processors are 16-bit processors (this refers to the internal bus width and register width) , their memory interface is working on a byte basis. That is, each memory location carries one byte.

For the 8088 processors, each time the processor only fetches 1 byte from the memory. For 8086, things are a little bit complex. If a word is even addressed, it will be fetched in one access. Otherwise, a word will still be fetched in two cycles. Later in this course, you will learn in detail about this feature of 8086. A pin called BHE is used to manage this matter. You can look into it if you are interested. Or you can wait patiently till this stuff is covered in the lectures.

For 8088, there is no problem that the answer given is correct.

For 8086, even though sometimes a word can be fetched in one cycle, the format of that word in the memory is still "Lower byte at lower address". This has the advantage of compatibility over the other way around. The given answer is still correct.

In short, for 8086/8088 systems, it is always true that lower bytes are assigned to lower address. This is independant of the length of the data. This is a predefined convention.

Q.18.
Ans:
Q.19.
Ans:
Q.20.
Ans:
Q.21.
Ans: