| | |
Needing some guidance
![]() |
•
•
Join Date: Aug 2008
Posts: 55
Reputation:
Solved Threads: 1
To be upfront and all, this is indeed a homework assignment. But I'm not looking for anyone to write the code I need just help me with a few functions I'm needing to use (the book is VERY vague on how to use these instructions).
Assignment is open an encrypted file, decrypt it and then send it to a new text file.
Ok so far I have this
As I said the book is extremly vague on how these instructions truly work. My question is what is the normal procedure to open a file, read it and then output it to a new file?
Assignment is open an encrypted file, decrypt it and then send it to a new text file.
Ok so far I have this
Assembly Syntax (Toggle Plain Text)
.data BUFFER_SIZE = 5000 buffer BYTE BUFFER_SIZE DUP(?) filename BYTE "myfile.txt",0 (this is coming from my book) .code mov edx,OFFSET filename call OpenInputFile mov edx,OFFSET buffer mov ecx,BUFFER_SIZE call ReadFromFile call WriteToFile
As I said the book is extremly vague on how these instructions truly work. My question is what is the normal procedure to open a file, read it and then output it to a new file?
Last edited by RayvenHawk; 23 Days Ago at 2:06 pm.
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."
Programmers - Making other people rich for over 50yrs.
Microsofts saying: "If it ain't broke, update it so it will be."
Programmers - Making other people rich for over 50yrs.
•
•
Join Date: Dec 2007
Posts: 33
Reputation:
Solved Threads: 4
0
#2 23 Days Ago
Those functions could be in some library that I don't have, but perhaps writing those functions is the REAL assignment.
Could you give us some idea what assembler you use, on what operating system, etc? Maybe even the name of the course and book would give us a hint on helping you.
So far, your post doesn't give some of us enough info, unless those functions happen to belong to a package that someone else recognizes.
Could you give us some idea what assembler you use, on what operating system, etc? Maybe even the name of the course and book would give us a hint on helping you.
So far, your post doesn't give some of us enough info, unless those functions happen to belong to a package that someone else recognizes.
•
•
Join Date: Aug 2008
Posts: 55
Reputation:
Solved Threads: 1
0
#3 23 Days Ago
•
•
•
•
Those functions could be in some library that I don't have, but perhaps writing those functions is the REAL assignment.
Could you give us some idea what assembler you use, on what operating system, etc? Maybe even the name of the course and book would give us a hint on helping you.
So far, your post doesn't give some of us enough info, unless those functions happen to belong to a package that someone else recognizes.
The functions are built into the irvine32.lib, so writing the functions isn't part of the assignment.
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."
Programmers - Making other people rich for over 50yrs.
Microsofts saying: "If it ain't broke, update it so it will be."
Programmers - Making other people rich for over 50yrs.
•
•
Join Date: Dec 2007
Posts: 33
Reputation:
Solved Threads: 4
0
#4 23 Days Ago
Goto http://cis.ysu.edu/~rick/class3714/ch5.html and search for OpenInputFile and you will find the three functions documented near one another.
I see that you need to use EAX after that first call, the rest should follow naturally from the info at that URL. Give it a go, and let us know how it goes.
I have seen a lot of motion in the direction of making assembler behave similarly to other languages. Hard to say, but that irvine package might even ship with something similar to function prototypes to point you in the right direction. I have some masm stuff like that.
I see that you need to use EAX after that first call, the rest should follow naturally from the info at that URL. Give it a go, and let us know how it goes.
I have seen a lot of motion in the direction of making assembler behave similarly to other languages. Hard to say, but that irvine package might even ship with something similar to function prototypes to point you in the right direction. I have some masm stuff like that.
•
•
Join Date: Aug 2008
Posts: 55
Reputation:
Solved Threads: 1
0
#5 22 Days Ago
•
•
•
•
Goto http://cis.ysu.edu/~rick/class3714/ch5.html and search for OpenInputFile and you will find the three functions documented near one another.
I see that you need to use EAX after that first call, the rest should follow naturally from the info at that URL. Give it a go, and let us know how it goes.
I have seen a lot of motion in the direction of making assembler behave similarly to other languages. Hard to say, but that irvine package might even ship with something similar to function prototypes to point you in the right direction. I have some masm stuff like that.
Thanks for that link it really helped. I was able to read in a file and output it to a new one. Now I'm needing a little help with the 2nd half of the assignment.
We were given an encrypted file and we need to read it in and decrypt it using XOR (and the HEX decode number).
What's happening is it exports to a file, but it's a mixture of useless words and still some special characters. It's suppose to be a question for us to answer. Can you look at my code and see where I'm making my mistake?
Assembly Syntax (Toggle Plain Text)
INCLUDE Irvine32.inc .data BUFFER_SIZE = 5000 buffer BYTE BUFFER_SIZE DUP(?) robert BYTE "inputfile.txt",0 filenam BYTE "testing.txt",0 fileHandle DWORD ? bytesRead DWORD ? a1 DWORD ? .code main PROC ;--------------------------------------------------------; ; Open File ; ;--------------------------------------------------------; mov edx,OFFSET robert call OpenInputFile mov fileHandle,eax ;--------------------------------------------------------; ; Read file content into buffer ; ;--------------------------------------------------------; mov eax,fileHandle mov edx,OFFSET buffer mov ecx,BUFFER_SIZE call ReadFromFile mov bytesRead,eax mov eax,bytesRead ;-------------------------------------------------------; ; Copy content of buffer and decrypt ; ;-------------------------------------------------------; mov a1,edx xor a1,0ffh ;--------------------------------------------------------; ; Create output file and write buffer to file ; ;--------------------------------------------------------; mov edx, OFFSET filenam call CreateOutputFile mov fileHandle,eax mov eax,fileHandle mov edx,OFFSET buffer mov edx, a1 ; Copy decryted information into EDX mov ecx,BUFFER_SIZE call WriteToFile mov bytesRead,eax call CloseFile ; Close file exit main ENDP END main
Thanks.
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."
Programmers - Making other people rich for over 50yrs.
Microsofts saying: "If it ain't broke, update it so it will be."
Programmers - Making other people rich for over 50yrs.
•
•
Join Date: Dec 2007
Posts: 33
Reputation:
Solved Threads: 4
0
#6 22 Days Ago
A few items:
You XOR a DWORD with 0ffh, but you need to XOR each byte in the buffer, not some randomly chosen DWORD in memory.
So, point something at your buffer and XOR byte-wise for the length of the bufffer.
I see a general misunderstanding of the "write" function call when you put the offset to the buffer in edx, then immediately put your a1 variable into edx. Now the function could point at just about anything and start printing garbage.
Another thing. If your file is over 5000 bytes long, your program is inadequate. It should sit in a loop, reading and writing until it reaches the end-of-file (EOF).
You XOR a DWORD with 0ffh, but you need to XOR each byte in the buffer, not some randomly chosen DWORD in memory.
So, point something at your buffer and XOR byte-wise for the length of the bufffer.
I see a general misunderstanding of the "write" function call when you put the offset to the buffer in edx, then immediately put your a1 variable into edx. Now the function could point at just about anything and start printing garbage.
Another thing. If your file is over 5000 bytes long, your program is inadequate. It should sit in a loop, reading and writing until it reaches the end-of-file (EOF).
•
•
Join Date: Aug 2008
Posts: 55
Reputation:
Solved Threads: 1
0
#7 21 Days Ago
•
•
•
•
A few items:
You XOR a DWORD with 0ffh, but you need to XOR each byte in the buffer, not some randomly chosen DWORD in memory.
So, point something at your buffer and XOR byte-wise for the length of the bufffer.
I see a general misunderstanding of the "write" function call when you put the offset to the buffer in edx, then immediately put your a1 variable into edx. Now the function could point at just about anything and start printing garbage.
Another thing. If your file is over 5000 bytes long, your program is inadequate. It should sit in a loop, reading and writing until it reaches the end-of-file (EOF).
Old saying: "If it ain't broke don't fix it"
Microsofts saying: "If it ain't broke, update it so it will be."
Programmers - Making other people rich for over 50yrs.
Microsofts saying: "If it ain't broke, update it so it will be."
Programmers - Making other people rich for over 50yrs.
•
•
Join Date: Dec 2007
Posts: 33
Reputation:
Solved Threads: 4
0
#8 21 Days Ago
I don't have an assembler on this box, so I wrote this in the old MS-DOS debug command. That's why it looks a little funny, isn't optimal, whatever, but hey, we're just making the best of a bad situation.
I did this by word-sized chunks, not bytes.
The data at start is the first six characters starting at 200h:
0B0E:0200 9E 9D 9C 9B 9A 99 <= unprintable chars.
After running:
0B0E:0200 61 62 63 64 65 66 <= abcdef
I did this by word-sized chunks, not bytes.
Assembly Syntax (Toggle Plain Text)
0B0E:0100 B90300 MOV CX,0003 0B0E:0103 BB0002 MOV BX,0200 0B0E:0106 8B07 MOV AX,[BX] 0B0E:0108 35FFFF XOR AX,FFFF 0B0E:010B 8907 MOV [BX],AX 0B0E:010D 43 INC BX 0B0E:010E 43 INC BX 0B0E:010F 49 DEC CX 0B0E:0110 75F4 JNZ 0106 0B0E:0112 C3 RET
The data at start is the first six characters starting at 200h:
0B0E:0200 9E 9D 9C 9B 9A 99 <= unprintable chars.
After running:
0B0E:0200 61 62 63 64 65 66 <= abcdef
Last edited by dan63043; 21 Days Ago at 2:19 am. Reason: spelling
![]() |
Similar Threads
- Guidelines before posting (DaniWeb Community Feedback)
- student needing guidance on final exam code (C++)
- New to C and needing some guidance (C)
Other Threads in the Assembly Forum
- Previous Thread: Use string to call variable
- Next Thread: Noob looking for guidance
| Thread Tools | Search this Thread |





