943,762 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 980
  • Assembly RSS
Dec 15th, 2008
0

procedure size? Need halp

Expand Post »
so I have this working procedure that is basically like func. 09h of int 21h except it terminates at 00h, and it uses 01h-04h as control characters that determine the style of the text.

I wrote it in the main procedure of a test program to get it working, and then I put it in its own procedure in a larger program. When I run it from the larger program, I get this error:
"title: 16 bit MS-DOS Subsystem

Command Prompt - cmp
NTVDM has encountered a System Error
Access is denied.
Choose 'Close' to terminate the application
Close | Ignore"

I can't really ignore it. Anyways, I narrowed the cause of this error down to a procedure without a "RET" statement. But it has a return statement at the end. If I just put RET in the procedure, it runs, if I put all of the code back into the test program, it runs. So I'm thinking maybe there's a maximum size for a procedure? It is quite long, I haven't tried to slim it down at all, I'm not sure if I really can. Anyway, here's the procedure:

asm Syntax (Toggle Plain Text)
  1. outp proc
  2.  
  3. push cx
  4. push bx
  5. xor cx,cx
  6. xor bx,bx
  7. nexch: mov si,dx
  8. push dx
  9. add si,cx
  10. push cx
  11. mov al,[si]
  12. cmp al,00h
  13. jnz nndpr
  14. jmp endpr
  15. nndpr: cmp al,0dh ;LINE FEED
  16. jnz not0d
  17. mov ah,03h
  18. int 10h
  19. cmp dh,24d
  20. jz scwin
  21. inc dh
  22. mov ah,02h
  23. int 10h
  24. jmp gnext
  25. scwin: mov ax,0601h
  26. xor cx,cx
  27. mov dh,24d
  28. mov dl,79d
  29. mov bl,attrWHT
  30. int 10h
  31. jmp gnext
  32. not0d: cmp al,0ah ;CARRIAGE RETURN
  33. jnz not0a
  34. mov ah,03h
  35. int 10h
  36. mov dl,00h
  37. mov ah,02h
  38. int 10h
  39. jmp gnext
  40. not0a: cmp al,01h ;WHITE
  41. jnz not01
  42. mov bl,attrWHT
  43. mov attrCUR,bl
  44. jmp gnext
  45. not01: cmp al,02h ;GREEN
  46. jnz not02
  47. mov bl,attrGRN
  48. mov attrCUR,bl
  49. jmp gnext
  50. not02: cmp al,03h ;YELLOW
  51. jnz not03
  52. mov bl,attrHLT
  53. mov attrCUR,bl
  54. jmp gnext
  55. not03: cmp al,04h ;EDIT/HEADER
  56. jnz not04
  57. mov bl,attrEDT
  58. mov attrCUR,bl
  59. jmp gnext
  60. not04: mov ah,09h
  61. mov bl,attrCUR
  62. mov cx,01h
  63. int 10h
  64. mov ah,03h
  65. int 10h
  66. inc dl
  67. mov ah,02h
  68. int 10h
  69. gnext: pop cx
  70. pop dx
  71. inc cx
  72. jmp nexch
  73. endpr: pop bx
  74. pop cx
  75. ret
  76.  
  77. outp endp

I'm using TASM, and the model of the program is small... I tried making it "Large" and "Huge" to see how that would affect it but it said there was a problem with my call statement in the main procedure if I did (Forward reference needs override). Has anyone run into something similar to this? How can I fix it and make it work?
Reputation Points: 5
Solved Threads: 1
Unverified User
carson myers is offline Offline
33 posts
since Sep 2007
Dec 15th, 2008
0

Re: procedure size? Need halp

haaaaallllpppp

---moar---
okay so, I SUPPOSE I could do something like,

outp proc

jmp stprc
fnprc: ret
stprc:

...

jmp fnprc

outp endp

but isn't there another way around this?
Also, this seems to stick it in an infinite loop of sorts

---moar---

so it seems that when I add the ret at the beginning and then call it from the end (or just circumvent that ret and add another one at the end of the procedure) the program won't return from the procedure. The cursor just sits there, blinking, ctrl+c won't work, nothing will. I just have to close the prompt. when I add mov ax,4c00h and int 21h at the bottom the program exits properly, so it's not the code that's looping, it just...fails to do anything after that procedure. This is really odd, I have no idea how to fix it.
Last edited by carson myers; Dec 16th, 2008 at 12:00 am. Reason: MOAR
Reputation Points: 5
Solved Threads: 1
Unverified User
carson myers is offline Offline
33 posts
since Sep 2007
Dec 16th, 2008
0

Re: procedure size? Need halp

so I figured out if I pop the stack into ax at the very beginning of the procedure (the return pointer), move that value into a variable I have saved, then push it back, then at the end of the procedure, move the variable into ax and push it again, then it will return properly, so I suppose I'm just not unwinding the stack correctly... Still I wonder why access to the procedure is denied if the RET statement is too far away? I'd like to just put it at the end and save all those unnecessary jumps
Reputation Points: 5
Solved Threads: 1
Unverified User
carson myers is offline Offline
33 posts
since Sep 2007
Dec 16th, 2008
0

Re: procedure size? Need halp

It sounds like you are burrying your return adress on the stack. One potential problem is that you make four pushes and one path is to jump to endpr, which only makes two pops. so if you enter the procedure and al is not equal to 0 the first time through you jump directly to endpr and make two pops. This leaves two other values on top of the return address in the stack.
Last edited by jt_murphree; Dec 16th, 2008 at 4:30 pm.
Reputation Points: 34
Solved Threads: 2
Light Poster
jt_murphree is offline Offline
40 posts
since Dec 2008
Dec 16th, 2008
0

Re: procedure size? Need halp

thanks, it took me awhile to figure that one out, but it's fixed now. Any idea about the access denied error if the RET is at the bottom of the procedure?
Reputation Points: 5
Solved Threads: 1
Unverified User
carson myers is offline Offline
33 posts
since Sep 2007
Dec 16th, 2008
0

Re: procedure size? Need halp

Not sure about that one. It could be because the procedure is too long but that should be a long jump error. I have never encountered acess denied, of course I've never used tasm either. Actually, now that I think about it I think I have encountered that in masm but I can't remember what caused it. I want to say it is because I mispelled the name at either the the proc or endp statement but if your code is still as it is printed that is not the problem.
Reputation Points: 34
Solved Threads: 2
Light Poster
jt_murphree is offline Offline
40 posts
since Dec 2008
Dec 16th, 2008
0

Re: procedure size? Need halp

well it's not a problem with TASM, since TASM compiled it fine and I unassembled it in DOS and all looked fine. At first I thought it was just the original problem, with the stack not unwinding, and instead of the "return address" pointing to the actual return address it pointed to some place else in the memory and generated an access denied... I'm not sure that would even happen and of course now I know that's not the case anyways... Maybe my processor (or something) checks the next few instructions for a RET statement and if it's not there, abandons?
Reputation Points: 5
Solved Threads: 1
Unverified User
carson myers is offline Offline
33 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: bios level video instructions
Next Thread in Assembly Forum Timeline: Assembly Tutorial





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC