TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Asm-declaration – Embed assembly language code within a C++ program (2017)

45 点作者 ____Sash---701_将近 6 年前

11 条评论

siempreme将近 6 年前
In a string literal?!?! We did better almost 40 years ago..., this is assembly in turbo pascal:<p><pre><code> procedure init; assembler; asm mov ax,13h int 10h end; </code></pre> You can even have only the asm block in a regular pascal function and make use of regular arguments in the asm block.
评论 #20534988 未加载
评论 #20534666 未加载
评论 #20536917 未加载
评论 #20539092 未加载
评论 #20538306 未加载
clouddrover将近 6 年前
Lots of languages have inline assembly. Pascal does:<p>- Free Pascal: <a href="https:&#x2F;&#x2F;www.freepascal.org&#x2F;docs-html&#x2F;prog&#x2F;progch3.html#progse9.html" rel="nofollow">https:&#x2F;&#x2F;www.freepascal.org&#x2F;docs-html&#x2F;prog&#x2F;progch3.html#progs...</a><p>- Delphi: <a href="http:&#x2F;&#x2F;docwiki.embarcadero.com&#x2F;RADStudio&#x2F;Rio&#x2F;en&#x2F;Inline_Assembly_Code_Index" rel="nofollow">http:&#x2F;&#x2F;docwiki.embarcadero.com&#x2F;RADStudio&#x2F;Rio&#x2F;en&#x2F;Inline_Assem...</a><p>You can even do assembly in batch files via Debug if you really want to:<p><a href="https:&#x2F;&#x2F;thestarman.pcministry.com&#x2F;asm&#x2F;debug&#x2F;debug2.htm" rel="nofollow">https:&#x2F;&#x2F;thestarman.pcministry.com&#x2F;asm&#x2F;debug&#x2F;debug2.htm</a><p><a href="https:&#x2F;&#x2F;www.robvanderwoude.com&#x2F;debug.php" rel="nofollow">https:&#x2F;&#x2F;www.robvanderwoude.com&#x2F;debug.php</a>
评论 #20534523 未加载
评论 #20534571 未加载
bregma将近 6 年前
Odd bit of news reporting on something that was part of a standard published in 1997. What&#x27;s next, breaking news on a standard 7-bit code used by Americans for information interchange?
评论 #20534909 未加载
haberman将近 6 年前
I don&#x27;t see anything on that page referencing C++20. Am I missing something?<p>On a related note, I always find the official docs for GCC inline assembly are insufficient for figuring out what I am trying to do. I nearly always have to resort to dumb trial and error. I was just recently planning to write some docs of my own on the subject. Not tutorial docs, but reference docs.
评论 #20535708 未加载
评论 #20536814 未加载
dvt将近 6 年前
Years ago, I started work on a library that does this in Java: <a href="https:&#x2F;&#x2F;github.com&#x2F;dvx&#x2F;jssembly" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dvx&#x2F;jssembly</a><p>The syntax looks like this:<p><pre><code> jsm.define(&quot;test&quot;, new Block(x64) {{ __asm( &quot;nop&quot;, &#x2F;&#x2F; no-op &quot;ret&quot; &#x2F;&#x2F; return ); }}).invoke();</code></pre>
basementcat将近 6 年前
Tangentially related but in gcc and clang you can jump to or call machine language embedded within string literals.<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;48593734&#x2F;calling-goto-on-a-wide-char-string-in-c-gcc&#x2F;49063073#49063073" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;48593734&#x2F;calling-goto-on...</a><p><a href="https:&#x2F;&#x2F;codegolf.stackexchange.com&#x2F;questions&#x2F;2203&#x2F;tips-for-golfing-in-c&#x2F;104999#104999" rel="nofollow">https:&#x2F;&#x2F;codegolf.stackexchange.com&#x2F;questions&#x2F;2203&#x2F;tips-for-g...</a><p>This is <i>not</i> recommended for anything in production but is an amusing parlor trick.<p>Edit: Recent toolchains may require the -zexecstack flag to avoid a segfault.
mbel将近 6 年前
Old, well-known feature of one of the most popular languages. I must be missing something, because I have no idea how this became a hacker &quot;news&quot; :)
评论 #20535098 未加载
评论 #20535268 未加载
评论 #20535902 未加载
raviolo将近 6 年前
The real question remains unanswered: why is this on the front page?
评论 #20535369 未加载
bla3将近 6 年前
Maybe what&#x27;s new here is the suggestion of using a raw string literal for the assembly source? That does look neat (if minor).
评论 #20535796 未加载
mud_dauber将近 6 年前
I was a Forth dev a long time ago (on a planet far away...). Switching to &amp; from assembly seemed as natural as breathing. Oh for the days of 16bit cores and minuscule register banks.
lawlessone将近 6 年前
did this in college over 10 years ago..