My Book" Microprocessors and Microcontrollers" is doing fine by the good wishes of students and teachers. It has review questions after each chapter and these are quite a lot in number , they are also useful for exam preparation. Apart from these JNTU OU question papers were refered and the list below is the question bank. we will update it regularily. (ALS/KSA/GKR/CRS-GNITS) pagecontents
1. question bank 2.procedures stack relocation linking 3.Calculator -example of external linking 4.cupid 5.cmpxchg8b 6.rdtsc 7. 4th mid exam 99batch 8. 5th mid exam 99batch 9.return to main page
This is an example program to design a menu driven ALP and also show the features of
modular program development using linking and relocation.
The student is expected to assemble the five programs separately and study the .lst file
and locate the relocation information which is incomplete with the address of the external module/variable not assigned any specific value (except 0000) and a suffix R /E indicating that this is going to be assigned at loading time by the LOADER.
The Linker links the five modules CALCU.obj ADDER.obj,DIVD.obj,MULT.obj SUBB.obj and
assigns relative addresses.
The LOADER will assign the absolute addresses at run time depending on the memory
availability to the OS.
TITLE is an assembly directive where the rest of the line is ignored by the assembler for
assembly this is used to give the name of the file/program. Usually it is a good practice to
keep the same name for the File and the Main module contained in it.
The Module which has the .startup directive or the end label(start address) will be the
main module called by its name.
Make sure that after every assembly level modification the assembler is used to generate
the .obj. Ensure that after all .objs are ready that they are LINKED together typically with
the Main module file first.
Inspect the .lst file after each assembly specially looking for relocation items. During
debugging view the CPU contents as this will give the comprehensive picture of the calling
modules and called modules showing the mnemonic assembly language. Keep the option zi/la
for source level debugging & listing all items during assembling, follow the same for
linking by using /v for source level debugging.
Debug the entire program and check whether input numbers more than 32,767 can be given for
both the input values.
DANGER only module ADDER.ASM is debugged!!!!!!!! DIVD.ASM,MULT.ASM,SUBB.ASM have not at all
been tested so understand ADDER.ASM and use it as key to implement/debug the last three
modules.
back to page contentsTITLE CALCU.ASM
EXTRN ADDER:near,MULT:near,divd:near,subb:near .model tiny printf macro string mov ah,09h mov dx, offset string int 21h endm getch macro mov ah,01 int 21h endm .stack 160 .data menu db 0ah,0dh,' A Simple Calculator' db 0ah,0dh,' 1. addition' db 0ah,0dh,' 2. subtraction' db 0ah,0dh,' 3. multiplication' db 0ah,0dh,' 4. division' db 0ah,0dh,' X. exit the program' db 0ah,0dh,' input your choice ?$' addproc db 0ah,0dh,' addition procedure?$' subproc db 0ah,0dh,' subtraction procedure?$' divproc db 0ah,0dh,' division procedure?$' mulproc db 0ah,0dh,' multiplication procedure?$' num1 dw 0 num2 dw 0 PRESSANYKEY DB 0AH,0DH,'PRESS ANY KEY $' binnum dw 0;accessed by asc2bin overflowdmsg db 0dh,0ah, 'overflow error $'; invalidmsg db 0dh,0ah, 'invalid error $'; enternum db 0dh,0ah, 'please type a number less than 32000 $';from asciinum db '00000$';getnum binout dw 0ffffh RESULT DB 0AH,0DH,0DH,0AH,0AH,0DH,0DH,0AH,0AH,0DH,0DH,0AH,'THE RESULT IS ' ascout db '00000',0AH,0DH,0DH,0AH,0AH,0DH,0DH,0AH,0AH,0DH,0DH,0AH,'$' .code .startup begin: mov ax,@data mov ds,ax menuagain: printf menu getch cmp al,'1' jne nxt1 call addition jmp menuagain nxt1: cmp al,'2' jne nxt2 call subtract jmp menuagain nxt2: cmp al,'3' jne nxt3 call divide jmp menuagain nxt3: cmp al,'4' jne nxt4 call multiply jmp menuagain nxt4: cmp al,'X' jne menuagain .exit asc2bin proc mov cx,5 ;put number of digits in cx mov di,10 ;put base 10 in di to multiply acc with mov bh,'9' ;bh to check if number greater than 9 mov bl,'0' ;bl checks lower limit of number mov si,offset asciinum xor ax,ax ; make accumulator zero A2Bagain: mul di jc overflow mov dx,ax ; save multiply accumulate reister AX mov al,[si] cmp al,bl jl invalid cmp al,bh jg invalid sub al,30h cbw add ax,dx jc overflow inc si loop A2Bagain over: mov binnum,ax ret invalid: PRINTF invalidmsg PRINTF PRESSANYKEY GETCH jmp BEGIN overflow: PRINTF overflowdmsg PRINTF PRESSANYKEY GETCH jmp BEGIN asc2bin endp bin2asc proc xor si,si mov di,offset ascout add di,4 mov ax,binOUT MOV DX,0 mov bx,10 mov cx,5 ba: div bx add dl,30h mov [di],dl dec di xor dx,dx loop ba RET bin2asc endp getnum proc mov ah,9 mov dx,offset enternum int 21h mov si,offset asciinum mov cx,5 GNagain: mov ah,01 int 21h mov [si],al inc si loop GNagain ret getnum endp multiply proc call getnum call asc2bin mov ax,binnum push ax call getnum call asc2bin mov ax,binnum push ax call mult pop ax pop bx add ax,bx mov binout,ax call bin2asc ret multiply endp subtract proc call getnum call asc2bin mov ax,binnum push ax call getnum call asc2bin mov ax,binnum push ax call subb pop ax pop bx add ax,bx mov binout,ax call bin2asc ret subtract endp divide proc call getnum call asc2bin mov ax,binnum push ax call getnum call asc2bin mov ax,binnum push ax call divd pop ax pop bx add ax,bx mov binout,ax call bin2asc PRINTF RESULT ret divide endp addition proc call getnum call asc2bin push binnum call getnum call asc2bin push BINNUM CALL ADDER pop ax pop bx ; add ax,bx mov binout,ax call bin2asc PRINTF RESULT ret addition endp END *************************************TITLE ADDER.ASM; MODULE EXTERNAL ************************************* .model tiny .code adder proc push bp mov bp,sp add bp,6 mov ax,[bp] dec bp dec bp mov bx,[bp] add ax,bx mov [bp],ax xor bx,0 inc bp inc bp mov [bp],bx ret adder endp end ************************************* TITLE DIVD.ASM MODULE EXTERNAL ************************************* public divd .model tiny .code divd proc near push bp mov bp,sp add bp,6 mov ax,[bp] dec bp dec bp mov bx,[bp] div bx mov [bp],ax inc bp inc bp mov ax,0 mov [bp],ax pop bp ret divd endp end ************************************* TITLE MULT.ASM MODULE EXTERNAL ************************************* public mult .model tiny .code mult proc near push bp mov bp,sp add bp,6 mov ax,[bp] dec bp dec bp mov bx,[bp] mul bx mov [bp],ax inc bp inc bp mov ax,0 mov [bp],ax pop bp ret mult endp end ************************************* TITLE SUBB>ASM MODULE EXTERNAL ************************************* public subb .model tiny .code subb proc near push bp mov bp,sp add bp,6 mov ax,[bp] dec bp dec bp mov bx,[bp] sub ax,bx mov [bp],ax inc bp inc bp mov ax,0 mov [bp],ax pop bp ret subb endp end
back to page contentscpuid
TITLE CPUID.ASM .MODEL TINY .586 PRINTF MACRO DMES MOV AH,9 LEA DX,DMES INT 21H ENDM LF EQU 0AH CR EQU 0DH ; CPUID INSTRUCTION WHEN EXECUTED WITH EAX=0 ; - GETS "GENUIINE INTEL " IN ECX:EBX:EDX IF CPU IS INTEL PENTIUM ; ELSE RETURNS EAX=1 FOR OTHER CPU'S ; CPUID INSTRUCTION WHEN EXECUTED WITH EAX=1 ; EAX BITS 3-0= NUMBER OF THE STEPPING ID ; EAX BITS 7-4= MODEL NUMBER ; EDX BIT 0 ='CPU CONTAINS FPU' ; EDX BIT 1 ='ENHANCED 8086 VM SUPPORT" ; EDX BIT 3 ='PAGE SIZE EXTENSION SUPPORTED" ; EDX BIT 4 ='TIME STAMP COUNTER SUPPORTED" ; EDX BIT 8 ='CMPXCHG8B SUPPORTEDSUPPORTED" ; EDX BIT 9 ='3.3VOLT POWER SUPPLY MICROPROCESSOR" .STACK 64 .DATA cpumanuf db CR,LF,' this is the ----' pmsg db '000000000000$' stid db CR,LF,'Stepping number : ' sid db '00$' cpm db CR,LF, 'CPUMODEL : ' CPUMODEL DB '00$' CF DB CR,LF, 'CPUCONTAINSFPU$' E86VMSUP DB CR,LF, 'ENHANCED 8086 VM SUPPORT$' PSES DB CR,LF,, 'PAGE SIZE EXTENSION SUPPORTED$' TSCSUP DB CR,LF,, 'TIME STAMP COUNTER SUPPORTED$' ps33 db CR,LF,, '3.3 volts microprocessor$' cmpxch8 db CR,LF,, 'compare & exchange 8 bytes supported$' CPUCONTAINSFPU EQU 0 ENHANCED8086VMSUPPORT EQU 1 PAGESIZEEXTENSIONSUPPORTED EQU 3 TIMESTAMPCOUNTERSUPPORTED EQU 4 CMPXCHG8BSUPPORTEDSUPPORTED EQU 8 PS33VOLTMICROPROCESSOR EQU 9 .CODE .STARTUP MOV AX,@DATA MOV DS,AX MOV EAX,0 CPUID mov dword ptr [pmsg],ebx mov dword ptr [pmsg+4],edx mov dword ptr [pmsg+8],ecx printf cpumanuf MOV EAX,1 CPUID PUSH EAX push edx AND AX,0FH MOV BL,10 DIV BL MOV SI,OFFSET sid add al,30h mov [si],al inc si add ah,30h mov [si],ah pop eax and ax,0f0h mov cl,4 rol al,cl AND AX,0FH MOV BL,10 DIV BL MOV SI,OFFSET cpumodel add al,30h mov [si],al inc si add ah,30h mov [si],ah printf stid printf cpm pop edx test edx,cpucontainsfpu je nxt1 printf cf nxt1: test edx,ENHANCED8086VMSUPPORT jne nxt2 printf E86VMSUP nxt2: test edx,TIMESTAMPCOUNTERSUPPORTED je nxt3 printf TSCSUP nxt3: test edx,PAGESIZEEXTENSIONSUPPORTED je nxt4 printf PSES nxt4: test edx,CMPXCHG8BSUPPORTEDSUPPORTED je nxt5 printf cmpxch8 nxt5: test edx,PS33VOLTMICROPROCESSOR je nxt6 printf ps33 ;nxt6: test edx,TIMESTAMPCOUNTERSUPPORTED ; je nxt7 ; printf TSCSUP nxt6: .EXIT END ************************************************************************************
cmpxchg8b
back to page contents
TITLE cmpx8.ASM .MODEL TINY .586 PRINTF MACRO DMES MOV AH,9 LEA DX,DMES INT 21H ENDM LF EQU 0AH CR EQU 0DH .stack 16 .data search dq '11111111' replace db '22222222' wordlist db '33333333' db '11111111' db '55555555' .code .startup mov ax,@data mov ds,ax mov ecx,4 mov esi,offset wordlist ag: push ecx mov eax,[esi] add esi,4 mov edx,[esi] mov ebx,dword ptr [replace] mov ecx,dword ptr [replace+4] cmpxchg8b search add esi,4 pop ecx loop ag .exit end ******************************************************************
rdtsc
back to page contentsTITLE rdtsc.ASM .MODEL TINY .586 PRINTF MACRO DMES MOV AH,9 LEA DX,DMES INT 21H ENDM LF EQU 0AH CR EQU 0DH .stack 16 .data cpuspeed equ 350 firstrdtsc dq 0 ttfe db cr,lf,' microseconds $' .CODE .STARTUP MOV AX,@DATA MOV DS,AX push edx push ecx db 0fh,31h ; op code for rdtsc instruction as borland is diplomatic mov dword ptr firstrdtsc,eax mov dword ptr firstrdtsc+4,edx