User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 425,873 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,403 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Feb 21st, 2005
Views: 7,428
Will demonstrate dumping the registers.
asm Syntax
  1. TITLE: Register Dump (RegDump.asm)
  2.  
  3. ;------------------------------------------------------------
  4. ; Name:
  5. ;
  6. ; Filename: RegDump.asm
  7. ;
  8. ; Project #: 2
  9. ;
  10. ; Completed: February 09, 2003
  11. ;
  12. ; Description: My second assembly program. Will demonstrate
  13. ; dumping the registers. Demonstrates problems
  14. ; from Assembly Language For Intel-Based Computers,
  15. ; 4th Ed. by Kip R. Irvine. Problems are #1 on pg.
  16. ; 96, #1 on pg. 133 and #7 and #8 on pg. 134.
  17. ;
  18. ; Reference: Assembly Language For Intel-Based Computers,
  19. ; 4th Ed. by Kip R. Irvine
  20. ;------------------------------------------------------------
  21. INCLUDE Irvine32.inc
  22.  
  23. .data
  24. val1 SDWORD 8
  25. val2 SDWORD -15
  26. val3 SDWORD 20
  27. source byte "This is the source string",0
  28. target byte SIZEOF source DUP(0)
  29. nameSize = ($ - source) - 1
  30. msgIntro byte "This is My Name's second assembly program and I will",0dh,0ah
  31. byte "demonstrate how to dump the registers using questions 1",0dh,0ah
  32. byte "on page 96, question 1 on page 133, and question 7 and 8",0dh,0ah
  33. byte "on page 134.",0dh,0ah
  34. byte 0dh,0ah,0
  35. msg1 byte "------------------------------------",0dh,0ah
  36. byte "Demonstrating question 1 on page 96.",0dh,0ah
  37. byte "------------------------------------",0dh,0ah,0
  38. msg2 byte "-------------------------------------",0dh,0ah
  39. byte "Demonstrating question 1 on page 133.",0dh,0ah
  40. byte "-------------------------------------",0dh,0ah,0
  41. msgAdd byte "Adding 0FFh and 1h in register al to set carry flag",0dh,0ah,0
  42. msgSub byte "Subtracting 3h from 2h in register ax to set carry flag",0dh,0ah,0
  43. msg3 byte "-------------------------------------",0dh,0ah
  44. byte "Demonstrating question 7 on page 134.",0dh,0ah
  45. byte "-------------------------------------",0dh,0ah,0
  46. msgExpr byte "Solving expression EAX = -val2 + 7 - val3 + val1",0dh,0ah,0
  47. msg4 byte "-------------------------------------",0dh,0ah
  48. byte "Demonstrating question 8 on page 134.",0dh,0ah
  49. byte "-------------------------------------",0dh,0ah,0
  50. normOrd byte "Normal order:",0dh,0ah,0
  51. revOrd byte "Reverse order:",0dh,0ah,0
  52.  
  53. .code
  54. main PROC
  55. ;///////Intro Message/////////////////////////////////
  56. mov edx,OFFSET msgIntro ;intro message into edx
  57. call WriteString ;display msgIntro
  58.  
  59. ;///////Question 1 on page 96/////////////////////////
  60. mov edx,OFFSET msg1 ;message 1 into edx
  61. call WriteString ;display msg1
  62. mov eax, 1000h ;1000h
  63. mov ebx, 4000h ;4000h
  64. mov ecx, 2000h ;2000h
  65. sub ebx, eax ;4000h-1000h = 3000h
  66. sub ebx, ecx ;3000h-2000h = 1000h
  67. call DumpRegs ;display the registers
  68. call WaitMsg ;use call WaitMsg from page 146 to pause
  69.  
  70. ;///////Question 1 on page 133/////////////////////////
  71. mov edx,OFFSET msg2 ;message 2 into edx
  72. call WriteString ;display msg2
  73.  
  74. ;Add to get carry flag
  75. mov edx,OFFSET msgAdd ;message Add into edx
  76. call WriteString ;display msgAdd
  77. mov al,0FFh
  78. add al,1h ;al=100h CF=1 Because result of add is 100 so only 00
  79. ;can go in the al register so the 1 is carried over
  80. call DumpRegs ;display registers
  81.  
  82. ;//Subtract to get carry flag
  83. mov edx,OFFSET msgSub ;message Sub into edx
  84. call WriteString ;display msgSub
  85. mov ax,2h
  86. sub ax,3h ;ax=FFFFh CF=1 Because larger int - from smaller int
  87. call DumpRegs ;display the registers
  88. call WaitMsg ;use call WaitMsg from page 146 to pause
  89.  
  90. ;///////Question 7 on page 134/////////////////////////
  91. mov edx,OFFSET msg3 ;message 3 into edx
  92. call WriteString ;display msg3
  93. mov edx,OFFSET msgExpr ;message Expr into edx
  94. call WriteString ;display msgExpr
  95. mov eax,val2 ;mov val2 FFFFFFF1h in eax
  96. neg eax ;change sign of val2 in eax 0Fh
  97. add eax,7 ;add seven to eax 016h
  98. sub eax,val3 ;subtract val3 from eax 02h
  99. add eax,val1 ;add val1 to eax 0Ah
  100. call DumpRegs ;display the registers
  101. call WaitMsg ;use call WaitMsg from page 146 to pause
  102.  
  103. ;///////Question 8 on page 134/////////////////////////
  104. mov edx,OFFSET msg4 ;message 4 into edx
  105. call WriteString ;display msg4
  106.  
  107. ;//Using part of (CopyStr.asm) Pg.130-131 for reference
  108. mov esi,0 ;index register
  109. mov ecx,SIZEOF source ;loop counter
  110.  
  111. L1: ;//Loop
  112. mov al,source[esi] ;get a character from source
  113. mov target[esi],al ;store it in the target
  114. inc esi ;move to next character
  115. loop L1 ;repeat for entire string
  116.  
  117. ;//Print in normal order
  118. mov edx,OFFSET normOrd ;message normOrd into edx
  119. call WriteString ;display normOrd
  120. mov esi,OFFSET target ;offset of variable
  121. mov ebx,1 ;byte format
  122. mov ecx,SIZEOF target-1 ;counter
  123. call DumpMem ;display the block of memory in hex
  124. call WaitMsg ;use call WaitMsg from page 146 to pause
  125.  
  126. ;//Using part of (RevString.asm) Pg.157-158 for reference
  127. ;//Print in reverse order
  128. mov edx,OFFSET revOrd ;message revOrd into edx
  129. call WriteString ;display revOrd
  130. mov ecx,nameSize ;push source on the stack
  131. mov esi,0
  132.  
  133. L2: ;//Loop
  134. movzx eax,source[esi] ;get character from source[esi] put in eax
  135. push eax ;push on stack
  136. inc esi
  137. loop L2
  138.  
  139. ;//Pop name in reverse and store in array
  140. mov ecx,nameSize
  141. mov esi,0
  142.  
  143. L3: ;//Loop
  144. pop eax ;get characters form eax
  145. mov source[esi],al ;store in string
  146. inc esi
  147. loop L3
  148.  
  149. mov esi,OFFSET source ;offset of variable
  150. mov ebx,1 ;byte format
  151. mov ecx,SIZEOF source-1 ;counter
  152. call DumpMem ;display the block of memory in hex
  153.  
  154. exit
  155. main ENDP
  156. END main
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 6:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC