flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
UniverseIsASimulation 11 Feb 2018, 14:05
Hey, guys!
I am trying to impress my informatics teacher by making a web-app that converts arithmetic expressions to the i486-compatible assembly. You can check my work here: Arithmetic expressions to assembly converter So, does it produce correct results? I've tried to test it, and to me it looks like it does, but I'll ask some experts on those things. |
|||
![]() |
|
revolution 11 Feb 2018, 18:20
I wanted to try this, but without JS it does nothing for me. However when examining the source the code looks good, indented and commented.
|
|||
![]() |
|
revolution 12 Feb 2018, 04:21
Not having JS is a choice I made.
|
|||
![]() |
|
tthsqe 12 Feb 2018, 11:05
Overflows the stack:
Code: a+(b+(c+(d+(e+(f+(g+(h+(i+(j))))))))) Reads past depth of stack (TBH, the AST is not right): Code: a+-b a*-b In general, I would say the parser has a problem with unary minus, and "a^b" can't be used in place of "pow(a,b)" If you can solve the problem of unary minus, would you like to contribute to my project? |
|||
![]() |
|
UniverseIsASimulation 12 Feb 2018, 19:41
Quote: Overflows the stack Thanks for pointing that out! I think I fixed it, there was an error in my implementation of the DFS algorithm (which is attempting to avoid the stack overflow by compiling the "deepest" parts of the expression first). Could you test it again, please? Quote: a+-b What's that supposed to do? As far as I know, it should issue a syntax error (and I haven't tried to implement that yet). Do you think it should parse the same as "a+(-b)"? That would be quite tough to implement. Quote: If you can solve the problem of unary minus, would you like to contribute to my project? Sorry, my knowledge of C and C++ is minimal. |
|||
![]() |
|
tthsqe 12 Feb 2018, 20:09
Good, now it does the inner first. However, it is impossible to avoid spill code. Some expressions simply need more than 8 registers. Consider a sum of 256 terms with the parenthesis placed so that the ast is a complete binary tree.
Any school girl the age of at least 7 knows that 2*-3 is -6 and not a "syntax error" |
|||
![]() |
|
UniverseIsASimulation 13 Feb 2018, 08:08
Quote: Consider a sum of 256 terms with the parenthesis placed so that the ast is a complete binary tree. I must admit I don't know what you are talking about. Quote: Any school girl the age of at least 7 knows that 2*-3 is -6 and not a "syntax error" Anyway, I've modified the tokenizer to tokenize the expressions such as "2*-3" as "2*(-3)". It does so by "splicing" those parentheses into the array. I don't know if that's possible in C++ though. |
|||
![]() |
|
UniverseIsASimulation 15 Feb 2018, 20:49
revolution wrote: Not having JS is a choice I made. Well, the code in that app is just 600 lines of JavaScript, so you can see for yourself that it's not a spyware, if you don't want to run it because you think it might be. Better yet, use a browser that doesn't do JIT compilation of JavaScript (such as the Internet Explorer 6), so that it's impossible to do the Meltdown or the Spectre attack. The less JavaScript a browser supports, the harder it is to make a spyware using the JavaScript it provides. |
|||
![]() |
|
revolution 16 Feb 2018, 02:45
UniverseIsASimulation wrote:
Anyhow, this off-topic might be best left to that other thread. |
|||
![]() |
|
UniverseIsASimulation 17 Feb 2018, 20:11
Does Tomasz mind me naming my website after Flat Assembler? Sorry I didn't ask before. It was supposed to be a metaphore. Like, if you write in assembly, you mustn't be sufficed with "surface" explanations, and I am supposed to give people a "deeper" perspective on some things. The domain assembler.000webhostapp.com was already taken, so I've chosen the domain name flatassembler.000webhostapp.com.
|
|||
![]() |
|
UniverseIsASimulation 28 Jun 2018, 11:19
Anyway, the web-app has been improved in many ways since I last posted here. I've implemented the error-handling (hopefully all syntax errors are covered and reacted to with an useful error message) and I've implemented some simple syntax-highlighting algorithm for assembly.
|
|||
![]() |
|
tthsqe 28 Jun 2018, 20:53
Ok. I will try to break it again.
![]() Btw, when really parsing, the approach of "splicing parenthesis in" doesnt seem like the best way to go. |
|||
![]() |
|
UniverseIsASimulation 11 Jul 2018, 16:19
Did you find some error? It's hard to believe there are none.
|
|||
![]() |
|
UniverseIsASimulation 09 Nov 2018, 18:37
Nevertheless, I've found some error. Create a program using that web-app that calculates "pow(x,2)". Assemble it and set the variable 'x' to be '-1'. It will output 'NaN', despite the fact that pow(-1,2)=1. The algorithm my web-app uses only works for x>0.
Is there a simple way to calculate "pow(x,y)" in Assembly if the 'x' is negative? It doesn't have to deal with complex numbers (such as the result of "pow(-1,1/2)"). BTW, if you don't trust me that my JavaScript code is not malicious, download it and work offline. Then it can't "phone home". |
|||
![]() |
|
revolution 09 Nov 2018, 19:10
If x is negative, then just make it positive and do the normal power function. Then, if y is an even integer, you are done. If y is an odd integer then return the negative of the result. If y is not an integer the return an error.
|
|||
![]() |
|
fasmnewbie 10 Nov 2018, 13:46
Universe
Use FABS against your base or BTR dword [your base's MSB],31 |
|||
![]() |
|
Furs 10 Nov 2018, 21:02
fasmnewbie wrote: Universe ![]() |
|||
![]() |
|
fasmnewbie 11 Nov 2018, 04:57
Furs, XOR is one of the way as well. But it is not descriptive of the problem being discussed here, that it resetting the sign bit.
When talking about MSB, I refer to the highest portion byte be it in Real8 or Real 4. See the keyword dword there? I wasn't being specific because it I don't know about the size of his float, but still even in Real8, you need to take out the DWORD portion. DWORD for float 4, DWORD+4 for QWORD. In whatever portion, the MSB holds the sign bit. |
|||
![]() |
|
Furs 11 Nov 2018, 10:42
I mean MSB = most significant byte. In your case it should be "most significant DWORD".
If you access the most significant byte (which is the float + 3, or double + 7) as a DWORD you'll access 3 bytes beyond the float and switch the sign bit of 3 bytes beyond the float. Crude diagram: Code: Float (bytes in memory, so little endian) / \ * * * * ^ ^ LSB MSB (sign bit is here) You access this: Float (bytes in memory, so little endian) / \ * * *[* ? ? ?] ^ You flip this byte's sign bit |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.