An Assembly Language program to print sequence of random numbers – IGNOU MCA Assignment 2014-15

By | July 19, 2014

MASTER OF COMPUTER APPLICATIONS
Course Code : MCSL-017
Course Title : C and Assembly Language Programming
Assignment Number : MCA(1)/L017/Assign/2014-15
Maximum Marks : 100
Weightage : 25%

 

Write a program in assembly language to print an infinite sequence of pseudo-random numbers. 

 

DATA SEGMENT
MSG1 DB 10,13,’RANDOM NUMBERS ARE : $’
MSG2 DB 10,13,’ $’
RES DB 10 DUP (‘$’)
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA DX,MSG1
MOV AH,9
INT 21H

LEA DX,MSG2
MOV AH,9
INT 21H
NXT:
MOV AH,2CH ; Set time function
INT 21H

MOV AX,DX ; DH=seconds,DL=hundredths of second
XOR AH,AH

LEA SI,RES
CALL HEX2DEC

LEA DX,RES
MOV AH,9
INT 21H

LEA DX,MSG2
MOV AH,9
INT 21H

JMP NXT

MOV AH,4CH
INT 21H
CODE ENDS

HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10

LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1

ADD AL,30H
MOV [SI],AL

LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP

END START

Program Code :

  1. DATA SEGMENT
  2. MSG1 DB 10,13,'RANDOM NUMBERS ARE : $'
  3. MSG2 DB 10,13,' $'
  4. RES DB 10 DUP ('$')
  5. DATA ENDS
  6. CODE SEGMENT
  7. ASSUME DS:DATA CS:CODE
  8. START:
  9. MOV AX,DATA
  10. MOV DS,AX
  11. LEA DX,MSG1
  12. MOV AH,9
  13. INT 21H
  14. LEA DX,MSG2
  15. MOV AH,9
  16. INT 21H
  17. NXT:
  18. MOV AH,2CH ; Set time function
  19. INT 21H
  20. MOV AX,DX ; DH=seconds,DL=hundredths of second
  21. XOR AH,AH
  22. LEA SI,RES
  23. CALL HEX2DEC
  24. LEA DX,RES
  25. MOV AH,9
  26. INT 21H
  27. LEA DX,MSG2
  28. MOV AH,9
  29. INT 21H
  30. JMP NXT
  31. MOV AH,4CH
  32. INT 21H
  33. CODE ENDS
  34. HEX2DEC PROC NEAR
  35. MOV CX,0
  36. MOV BX,10
  37. LOOP1: MOV DX,0
  38. DIV BX
  39. ADD DL,30H
  40. PUSH DX
  41. INC CX
  42. CMP AX,9
  43. JG LOOP1
  44. ADD AL,30H
  45. MOV [SI],AL
  46. LOOP2: POP AX
  47. INC SI
  48. MOV [SI],AL
  49. LOOP LOOP2
  50. RET
  51. HEX2DEC ENDP
  52. END START

Screen shots :-

Asm_program_Random_Number

After Execution :-

Asm_program_Random_Number_Out

Leave a Reply