[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/asm/ - Assembly Language General
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 26
Assembly language is awesome!
Discuss.
>>
>>55413629
bump because assembly is a topic not much discussed on /g/ while it should.
also. tried it on my raspberry and its easier than most people proclaim it to be
>>
Only learned basic LC3 and MIPS for school. What's a good assembler to start learning for srs?
>>
>>55413678

What languages do you know, and what would be a good precursor to assembly, if any?
>>
Is 8086 assembly recommended for a beginner?
>>
"assembly" isn't a language.
>>
>>55413733
It's all pretty much the same principles with the late 70's early 80's era processors so yeah sure.
>>
>>55413753
What is it then?
>>
What's the point of learning assembly when C exists?
>>
>>55413733
A Great assembly architecture to learn is MIPS. Search for Mars Simulator, it's a great tool to test MIPS programs.

A fun thing to do is writing a compiler for a toy language that generates MIPS code.

Anyway, 8086 is usually refereed to as x86 assembly. I don't know if it is easy for a beginner since I first learn MIPS, but give it a shot, it is always something interesting and useful to know,
>>
>>55413802
You can understand what the compiler is doing and know the computer at a deeper b level
>>
>>55413820
I suppose I shouldn't have asked "learned", allow me to restate my question: What's the point of writing assembly when C exists?
>>
>>55413629
I have a question. I know some Python and Java. Not anything amazing but I understand the basics.Made a shitty Swing program, etc.

How the fuck does one learn about assembly without some kind of CS background though?

I have a look at some tutorials and it starts talking about CPU registers as if I already know what the fuck they are. But I dont as I am self taught and mostly do it as a hobby.

I would love to know how to disassemble programs in IDA but I just don't know where the fuck to start learning.

Can someone help an anon out?
>>
>>55413844
That's a good question, I guess someone who likes assembly will prefer assembly over C.
>>
>>55413844
Reverse engineering
Application optimization
Direct map to hardware
Zero over-head
>>
>>55413844
You may need it for some very low level operations. Nearly everything today has a library that is better optimised than anything normal people will ever write though.
>>
>>55413844
It's fun to learn something new and to challenge yourself. There.
>>
>>55413844
What a weird question, but usually speed and control over execution flow, since you don't need to work with a higher level compiler.
For example the Linux kernel has a lot of inline assembly code, for certain critical paths that require precision and "unrolling" so to say.
>>
>>55413844
When:
- you have buggy compiler
- use faster new processor instruction (AVX, AVX2, etc)

Anyway, both case are implying you're writing inline asm, not from scratch.
>>
>>55413861
read these:

https://www-ssl.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

http://www.x86-64.org/documentation.html

http://ecee.colorado.edu/ecen4553/fall12/asm64-handout.pdf
>>
>>55413892
Ain't application optimization virtually always better handled by whatever compiler you're using? And C overhead is absolutely negligible. Reverse engineering is understandable, but that requires reading the code, not writing it.

>>55413905
Why ASM though? It's basically C except a dozen times more verbose. It's the opposite of fun.
>>
>>55413690
>>55413733
NASM is good to start out with, and then FASM makes everything like heaven.
https://www.youtube.com/watch?v=mWeh3_ITG7M
This guy is what I originally learned assembly from, as well as on tutorialspoint. Pretty informative and easy to follow, simple learning curve
>>
>>55413702
i know Go and C. but a good way to get to any sort of assembly would probably be JS > GO > C++ > C > ASM
>>
>>55413940
See >>55413946
>>
>>55413872
No, control and ease is the only reason these days.
While the compilers will produce highly optimized code, it just is sometimes too complicated and tedious to run the intermediary step of the compiler. You should think a C compiler as a function, which evolves and has implementations, so there is no set C compiler function that we can compare to. So understanding the results of the function will be hard and require deep knowledge, compared to doing it by hand.
Sometimes using assembly directly is just much simpler.
>>
>>55413946
You are right about C and the optimizations. Modern compilers are very proformant and out do most humans in most cases of optimization.

Although, there are times where the optimizations do not do as you wish. Sometimes it optimises could away something you wish it didn't.
>>
are the rules and syntax still same after all those years? same architecture and stuff?

i don't know much about this low level area but i always knew enough that its the most awesome and important
>>
>>55414003
I would propose the opposite route and starting with assembly, be it x86 or mips.
Languages have a lot of quirks, spending time with them, is less time spend on understanding processors and architectures.
>>
>>55414003
If you want to learn something just get right into it. You don't need to know c++ or even c to get into assembly.
>>
>>55414066
some of us would like some cool shit done after 4 hours. not 4 weeks
>>
>>55414046
Each processor architecture has it's opcodes aka the language the processor speaks, then we have compilers aka assemblers, that turn your assembly to those opcodes.
So each processor/architecture and each assembler to that architecture influence the syntax and rules.
>>
noice thread, i hope it doesn't die.
>>
>>55413629
I played TIS-100 for over 200 hours but somehow still have no idea what your pic related is doing or, more importantly, why it it's coded like that, did I get meme'd?
>>
>>55413629
>>55413970
Would anyone of you recommend C64? I would maybe eventually try and make a demo some day
>>
Why is NASM so fucking annoying with its syntax? I just want TASM for Linux, is that too much to ask?
>>
>>55414329
Never worked with C64 personally, don't really have a use for it since I can do everything in FASM generally; do post a link some time if you ever make something from it. From what I know it's a bit overly complex compared to most other assemblers though, people say it's a lot more difficult to learn but has some advantages
>>
>>55414310
It prints out the first 24 elements of the Fibonacci sequence.

Sorry about my formatting.
>>
But why
>>
>>55414357

Dos box is always a option.. Or I dunno you might try using nasm's -t option.
>>
>>55414398
Master over the hardware.
>>
Intel or AT&T syntax?
>>
>>55414444
I prefer gas AT&T syntax because It seems more explicit about whats going on in the code.
>>
>>55414329
The C64 is amazing to get started with ASM (or the superior stack based alternative). The problem is that the clean ISA of the 6510 will soften your stomach and you might puke your guts out when learning x86_64.
>>
>>55414468
I can't find a book that teaches with AT&T, but it's just a minor inconvenience
>>
>>55414444

Intel

At&t syntax is always painful to read. I see no reason to prefix constants with "$" and registers with "%".
>>
>>55414511
but what if I want a variable named rax? :$)
>>
>>55414511
faggot
>>
>>55413629
>at&t style
absolutely haram
>>
>>55414490

"Professional Assembly Language
Book by Richard Blum"

Its a good book.

It teaches IA-32(32 bit assembly )tho. The vast majority of the teachings translate over to AMD64(64 bit assembly).

When you know how to programming a 32 bit possessor learning 64 bit assembly will only take only a few references to read rather than having to relearn a whole new ISA. AMD64 is fully backwards compatible with IA-32 so everything you learn applies to your modern 64 bit possessor.
>>
>>55414444
LORD FOUR QUADS
>>
>>55414683
mirror mirror on the wall, which syntax is the best of all?
>>
>>55413861
You will probably like the book Computer Systems: A Programmer's Perspective. More specifically the third chapter
>>
>>55414834
Forgot about this book. I used to have the second addition for school. Was EVERY good. Very recommended.
>>
>/g/
>assembly
So meme thread?
>>
>>55414834
>Computer Systems: A Programmer's Perspective
cheers anon
>>
Just found this no HockeyNews.

http://ecee.colorado.edu/ecen4553/fall12/asm64-handout.pdf
>>
>>55413802
This was covered in my ASM class.
Basically we reviewed the code that single loop in C would generate. I can't remember what exactly was in the loop body but it was something relatively simple. It generated about 355 lines of assembly. I can write the same in about 12 lines of assembly.
So what's the point? Total control and speed.
It's why assembly is still preferred for satellites.
>>
>>55414357
What's wrong with NASM syntax?
>>
>>55415059
>It's why assembly is still preferred for satellites.
the main reason for this is because the satellite is running hardware that may not have a C compiler made for it
>>
>>55415107
That's a reason. Not the main reason.
>>
>>55414511
tfw AT&T will always be better than Intel
go suck a horsedick :)
>>
>>55413813
I did mips at college, it was awesome desu. Normies hated it though. For some reason never made a complier for what i remember, i guess my uni is kinda shit.
>>
File: 1394214374856.jpg (55 KB, 494x533) Image search: [Google]
1394214374856.jpg
55 KB, 494x533
>tfw when you crack every program you need because you spent all those nights learning reverse engineering when idiots your age went out to listen to some 1 2 3 3 2 1 music
>>
>>55415454
can you /denuvo/?
>>
>>55415454
Teach me your ways, master.
>>
Probably going to start a YouTube channel like terry writing and uploading code to my Allwiener A64 arm board in ASM and making my own meme OS, i'm excited guise
>>
>>55415524
Well, link the channel.
>>
>>55415524
share channel
>>
>>55415539
>>55415540
maybe later xd
>>
>>55415579
You filthy fucking tease.
>>
>>55415588
if you're a good boy maybe i'll indulge later~
>>
File: 1459033939230.jpg (140 KB, 500x667) Image search: [Google]
1459033939230.jpg
140 KB, 500x667
>>55415601
I-I'll be good.

What language are you gonna make your memeOS in? Terry made his own language. You gonna do the same?
>>
Writing code in assembly isn't magically faster than writing the same code in some other language. Compilers aren't stupid.
>>
>>55415630
good boys get large large buns and lollipops~

my plan is to make a nanokernel / exokernel in complete ARM64 assembly for performance reasons, and on top of that develop a C kind of an userland where I'll have advanced memory managament networking etc. I don't plan to write my own languages right now. I'll also be doing a 3d cheese pizza mmorpg (hope jewtube doesnt close my channel for that l0l)
>>
Is there a website with assembly programming challenges similar to exercism.io?
>>
>>55415661
Go get arrested, you sick fuck.
>>
>>55414634
I really don't like WROX books, most authors using this publisher like beating around the bush and when they do get to the topic at hand they omit a lot of useful information.
>>
>>55415682
someone's been molested as a child I take it
>>
>>55415663
I usually just look for generic programming challenges and do them in assembly.
>>
It's shit and the reason I dropped out of college.
>class made me use masm
>couldn't afford Windows
>too shy to go to computer lab to do work
>>
>>55415750
>not pirating
you must be trolling nigger
>>
>>55415750
Wow, you sound just like me.
>>
File: Academic Transcript.png (598 KB, 1036x2761) Image search: [Google]
Academic Transcript.png
598 KB, 1036x2761
>>55415761
Failed it twice, CSC 3410
>>
>>55413629
What's the best resource to learn assembly from?
>>
>>55415788
lmao
>>55415794
what processor
>>
>>55415827
>what processor
You mean architecture.
>>55415788
M8, wtf? I have a pretty shitty transcript but I can tell you're smart. You just took a sudden downturn one semester. That's a classic symptom of depression, maybe you should talk to someone.
>>
>>55415827
x86_64
>>
File: autismspeaks.png (10 KB, 280x336) Image search: [Google]
autismspeaks.png
10 KB, 280x336
>>55415861
>You mean architecture.
>>
File: 1454471569903.jpg (110 KB, 759x508) Image search: [Google]
1454471569903.jpg
110 KB, 759x508
>>55415914
Do you want to do GAS, MASM, NASM, or FASM?
>>55415918
>be wrong
>get corrected
>attack the other person
>>
>>55415914
if you're on lunix
http://docs.cs.up.ac.za/programming/asm/derick_tut/
else
http://wiki.osdev.org/Bare_Bones
>>
>>55415933
What would you recommend for a beginner?
>>
>>55415952
Well I hate AT&T syntax so GAS is out. MASM is windows only and is just ugly. So either NASM or FASM and NASM is most popular so you'd find more support and assistance that way.
Actually the official NASM documentation on their website is pretty good for just starting out but that's assuming you're already fairly decent with computer science.
>>55415974
>>corrected
>implying
>>
>>55415952
do nasm
>>
is there an explanation of 6502 interrupts out there that's not completely fucking nebulous and isn't "well, uh the computer waits!"

like how do i use it and what's the practical use for one
>>
>>55415750

Masm runs flawlessly in Wine, Anon. Are you retarded?
>>
Assembly is more tedious than difficult and it makes sense in only very few cases, mostly for SIMD code.
Even drivers and mostly written in C
>>
File: 1424107262080.jpg (101 KB, 399x388) Image search: [Google]
1424107262080.jpg
101 KB, 399x388
>>55416050
>6502 assembly

Anyway, can't help you out with that. Could help with x86 interrupts. Unless you mean you, in general, don't understand what an interrupt is.
>>
>>55416113
just like SIMD there are some instructions the compiler won't use that might improve performance and there are places where C remains too abstract anon, thats where ASM provides performance
>>
>>55413892
>Reverse engineering
This. Leet haxor jobs that pay $250k starting require expert knowledge of C, Assembly, IDA, Linux, Networking Protocols, Malware Analysis, Exploit Development, pretty much everything that /g/ neckbeards love, but you have to be able to read generated Assembly code like it's a leisurely novel.
>>
>>55413629
This is the best I can do. No comments because I didn't include them when I wrote this in 10th grade.
mov ah,2
int 10
mov ax,a01
mov cl,1
int 10
xor ah,ah
int 16
cmp al,61
je 0121
cmp al,64
je 0125
cmp al,77
je 0129
cmp al,73
je 012d
jmp 0100
dec dl
jmp 0100
inc dl
jmp 0100
dec dh
jmp 0100
inc dh
jmp 0100
>>
>>55416402
What is this even supposed to do?
The interrupts you're using, is this meant to be run in Real-Address mode? Is this bootable?
>>
>>55413629
Reminder that if you use intrinsics YOU ARE A PUSSY AND DESERVE TO EAT THE SHIT YOU SHIT.
yasm + x86utils.asm (from x264/avutils/everywhere) = god race
>>
>>55416467
>x86utils.asm
?
>>
>>55416456
>What is this even supposed to do?
It draws the ASCII character code 1 smiley face and you can move it around the screen with the wasd keys.

>The interrupts you're using, is this meant to be run in Real-Address mode? Is this bootable?
I assembled it using DEBUG.COM back when it was included with Windows. It isn't bootable, I'm pretty sure at least one of the interrupts was dependent on Windows.
>>
>>55416519
Collection of macros to help with SIMD. Auto replaces the register names with whatever mode (MMX, SSE, AVX) you want, shuffles, swaps, butterflies, anything you'll often use.
>>
>>55416093
The resulting binaries would always be all fucked up when it came to line endings in input. Like I could make it work on my machine but then on Windows it would be all fucked up; likewise if it worked on Windows it would be fucked up on Loonix.
>>
>>55416575
>using someone else's macro
>still shits on them for using intrinsics
>>
File: 123.png (165 KB, 1265x534) Image search: [Google]
123.png
165 KB, 1265x534
>>55416050
An interrupt in the mos 6502 is like a function call that sets the program counter to the interrupt vector, or 0xFFFE to be precise. When an interrupt occurs, the program counter and status register are pushed to the stack in that order and the interrupt disable bit is set.

For a concrete example, the Vic-20 has two timers that count down, when either timer reaches 0 an interrupt is requested. If the processor is not already executing an interrupt and if interrupts are enabled, the process I described above occurs.
>>
>>55416402
>>55416456
>>55416552
Pic of it running. I remember I had a problem getting the screen to clear so I just left that out.
>>
>>55416552
How fucking long ago were you in high school? Unless I'm mistaken, because I only use Linux, Windows overrides all interrupts. The lowest they offer is int 21h.
If you're in Real-Address mode then int 10h is for writing a char and int 16h is for reading a char.

Or, maybe, I have no fucking idea what I'm talking about. It's been a while since I played with assembly.
>>
>>55416609
>letting the compiler manage registers for you
Next time your code's slow as fuck on any other computer don't complain, boy.
Getting your hands dirty is the only way to write efficient and fast code. Might as well use whatever as long as you don't go high level.
>>
>>55416720
I do get my hands dirty. Without using someone else's shitty macros. I write my own shitty macros, thank you very much!
>>
I don't think programming in assembly is a challange, it's just tedious.
Designing a better algorithm for one of many computational problems is challanging, but /g/ doesn't seem to care about it at all.
>>
>>55416731
>code duplication
>non generic macros
Next time your shitty asm gets replaced by some dumb instrinsics someone wrote in an hour and are 20% slower and larger you'll have yourself to blame.
>>
>>55416779
>>
>>55416779
Listen, big professional ASM man guy.
Why don't you show me some of your great code!
Post some.
>>
asm is pointless unless you're bypassing a bug with your compiler which probably isn't happening unless you're working on an extremely niche architecture with limited compilers available to you
>>
>>55416654
>How fucking long ago were you in high school?
I wrote that in the late 2000s when I was bored.

>If you're in Real-Address mode then int 10h is for writing a char and int 16h is for reading a char.
That's in Real-Address mode then, I must have been wrong about Windows being required.
>>
>>55416770
>Designing a better algorithm for one of many computational problems is challanging, but /g/ doesn't seem to care about it at all.
That's largely because pretty much all of the good Hello World and Fizzbuzz algorithms have been discovered already.
>>
File: 1458600321067.png (215 KB, 469x348) Image search: [Google]
1458600321067.png
215 KB, 469x348
>>55416803
You don't have to look far, if you're watching a video you're likely using it right now.
>>
>>55416860
Big man, no code
>>
>>55416860
Oh, okay, bud.
>>
>>55416845
>I wrote that in the late 2000s when I was bored.
Ah.
>That's in Real-Address mode then, I must have been wrong about Windows being required.
It's definitely Real-Address, I just wasn't aware MS-DOS allowed you to use interrupts.
>>
>>55413629
who /customOS/ here?
>>
>>55416936
Think it might be bootable then? I have an old 286 laptop sitting around that has a monitor that allows you to enter machine code directly and run it and the assembled code is only 49 bytes so it wouldn't take long to punch in.
>>
x86 is literally the worst thing ever invented. I bet if Intel allowed us to write micro code directly, it would make the code LESS ugly and more easily comprehensible.
>>
>>55413844
For systems development on x86, the early boot stage of the system is best written in assembly when you instructions such as lgdt. Efficiency is also another reason, as you control tbe size of the binary. The first part of your OS has to be 512 bytes in size..
>>
>>55417086
It's not, I tried. There's some problems with it.
The interrupts take more "parameters". I didn't want to mess with it because you used jmp with specific places in code instead of using labels.
Also, is
>a01
Supposed to be A01 hex?
>>
>>55414357
Be glad it isnt GNU syntax. That shit is fucked. Intel syntax is objectively the best.
>>
>>55417123
>Supposed to be A01 hex?
Yeah.
>>
>>55416236
>IDA
>mfw in older books about "security" it was considered script-kiddie shit
>>
>>55417146
Ah, NASM doesn't let you do that and MASM doesn't either. You either have to do 0xA01 or 0A01h. The first part can't be a letter because it's going to think it's a register.
>>
>>55417146
I got it to boot but it still doesn't work. It's because the interrupts were employed properly.

    mov ah,2
int 10h
mov ax, 0A01h
mov cl,1
int 10h
xor ah,ah
int 16h
cmp al,61
je 0121
cmp al,64
je 0125
cmp al,77
je 0129
cmp al,73
je 012d
jmp 0100
dec dl
jmp 0100
inc dl
jmp 0100
dec dh
jmp 0100
inc dh
jmp 0100

times 510-($-$$) db 0
dw 0xAA55
>>
>>55417146
>>55417241
What I mean is it doesn't let you move the mouse all around. It prints a single smile and then does nothing more.
>>
File: notepad_2016-07-04_20-01-38.png (645 KB, 1271x3800) Image search: [Google]
notepad_2016-07-04_20-01-38.png
645 KB, 1271x3800
r8?
>>
>>55417258
>masm
REEEEEEE

It's nice. I just wish you were a bit more consistent with your white space.
>>
>>55413629
where can i teach myself x86 asm?
>>
>>55417345

> he can't read asm so he comments on the whitespace
>>
>>55417380
What assembler do you want to use? Check: >>55415933 and >>55416016. They're all x86 but with uniqueness.
>>55417441
I have clinically diagnosed OCD. I can read your assembly just fine it just bothers me. Besides, your code is beautifully commented, even someone who can't read asm would be able to follow along.
>>
>>55417469
i would say NASM or MASM? i'm not sure, i don't really know what difference it makes, i just know i've heard of NASM/MASM before. what difference does compiler make? i would assume that the ASM would be the same, no?
>>
>>55413802
>>55413844
You shouldn't need C for anything but legacy code. There's no reason why C is better than any other language without GC like Ada or Pascal for systems programming. C is worse in a lot of ways.

>>55413946
>Why C though? It's basically JavaScript except a dozen times more verbose. It's the opposite of fun.
>>
>>55417649
>compiler
Assembler not compiler.

Anyway, the biggest problem is that MASM is windows only. Other than that MASM simplifies some things but makes other things unnecessarily convoluted. MASM makes you need to make full on procedure headers but NASM doesn't. MASM makes sending stack parameters easier but the code needed to do so is quite verbose. My college taught MASM but then I switched to NASM so you can easily switch in between. NASM is "cleaner" though.
>>
>>55417706
whoops, my bad. thank you for clarifying the importance of choosing a good assembler. can you recommend any good resources to learn NASM then? i already bookmarked the video posted earlier.
>>
>>55417804
Because so many college students learn it, tons of professors have their lessons on their website. You can pretty much google whatever you're looking for. The official NASM documentation on their website is pretty good assuming you already know computer science terminology. Tutorialpoint's is fairly decent for getting started.
>>
>>55417852
awesome, thanks a lot.
>>
>>55417872
Are you on linux or windows?
Also, you'll probably want to use the C library for output as it's simpler when just starting off.
>>
>>55417898
windows primarily but i have a linux install as well. i've done a tiny bit of assembly in the past while reading Hacking: The Art of Exploitation, but i really want to buckle down and learn x86 asm proper and do some baby's first reverse engineering just for fun.
>>
>>55417929
Ah, so yeah. You could use the C library for I/O since that is easiest or you could use DOS' int 21h.
> i've done a tiny bit of assembly in the past
How in depth is a tiny bit?
>>
>>55417945
i understand the basic concepts of registers, the stack/heap and simple instructions. i just don't really know how to do anything meaningful in assembly. its almost more of a conceptual issue than practical. like, how do you go from basic arithmetic in assembly to drawing pixels on a screen? is it like, editing video memory? i just don't get how assembly is used to perform meaningful interactions with the system beyond just arithmetic and pushing memory around.
>>
>>55415454
>tfw when you crack every program you need because you spent all those nights learning reverse engineering when idiots your age went out to listen to some 1 2 3 3 2 1 music

So those cracks for applications like Ableton Live and Adobe PS were done with assembly?
>>
>>55418028
> how do you go from basic arithmetic in assembly to drawing pixels on a screen?
Depends how low you want to go. The benefits of living in CURRENT YEAR is that there are tons of libraries to simplify it. Windows has an API that makes GUI extremely easy. But you can choose to stay on a very low level from which you can actually draw to the screen. It's much more direct. You have to deal with paging in memory and manual determine how you want to draw to the screen. If in Real-Address mode you are directly sending messages to the computer without any protection of a modern os. For this, you can use BIOS interrupts.
If you ever experiment in making an OS you'll need to use these.
Here's all of them: http://ctyme.com/intr/int.htm
>>
>>55418119
thank you! great resources in this thread!
>>
C made assembly obsolete for 40 years now
only neckbeard enthusiasts do it for 1337 cred
>>
>>55418190
Keep in mind, I don't think windows will let you enter Real-Address mode.
>>
>>55418211
>only neckbeard enthusiasts do it for 1337 cred
Most colleges require it because you should know how to use it. Not to become a professional assembly programmer but because you should understand the underlying way computers work.
Further, satellites are still programmed in assembly. NASA is still hiring assembly programmers.
Even more so, certain things can only be done in assembly. Most modern operating system are ASM + C.
>>
>>55413802
Dude. Look, if you apply for a programming job or if you are aiming to work in consultancy and you produce solutions in assembler, then you won't last one day. As the saying goes, why use a sledgehammer to crack a nut?
>>
>>55413861
bro, assembler is used where other languages can't meet the ends. Don't use a sledgehammer to crack a nut. Don't ever use assembler in a business situation, ever. Even in college or university, they'll mark you down for it. Maybe, in electrical engineering to speed up a portion of code running slowly, embed assembler into it, but it will only get you one or two marks, if even.
>>
File: BJegWdR.jpg (33 KB, 500x551) Image search: [Google]
BJegWdR.jpg
33 KB, 500x551
not claiming to be a reverse engineering prodigy but i have NEVER seen code (even when run with maximum optimizations) that didn't contain inefficiencies in x86_64

http://www.cs.rochester.edu/users/faculty/sandhya/csc252/lectures/lecture-mi_optimizations.pdf

looking at the big picture of an entire piece of software optimizing everything is very expensive on processing power for compiler to do.

int a = 0;
...
blah blah blah (NOTHING THAT TOUCHES A IMPLICITLY OR EXPLICITLY)
...
a = user_input();

{
mov eax, 0;
...
blah blah blah (eax directly or indirectly not touched)
...
mov eax , (arbitrary user data)

}

the initial eax = 0 is useless. this is a small example but on the bigger picture by hand wins because compilers would take years or more to optimize to the level a human can with ingenuity.

https://en.wikipedia.org/wiki/RollerCoaster_Tycoon

this game was mostly written in assembly and parts in C to interface with windows so he didn't have to blow his brains out, which is why this game ran so beautifully on shit systems.

this doesn't mean by any means you should write software only in asm (maybe inline critical components like certain aspects of the main loop of a game, where a few instructions make a huge different because they are CONSTANTLY running.)
>>
What's the best resource for learning MIPS32 ASM?
>>
>>55418211
>JavaScript made C obsolete for 20 years now
>>
>>55415661
>falling for the non monolithic kernel meme
Just fuck my shit up.
>>
File: Screenshot_2016-07-05_08-41-11.png (109 KB, 1366x768) Image search: [Google]
Screenshot_2016-07-05_08-41-11.png
109 KB, 1366x768
>>55413629
Dabbling about AVR assembly these days, its a lot messier than 8052 assembly i used to play around with earlier. RISC is pretty annoying desu.
>>
>>55415107
Writing a compiler for such a system would be a minor problem. People write compilers all the time, be it for serious things or for fun. C doesn't specifically relies on any runtime feature, such as GC or dynamic memory allocation. So, basically, every system that accepts asm could theoretically accept C code, as it would be, in the end, nothing but asm code generated from a C source.

You could, however, have code size constraints or even speed constraints that could force you to use assembly.

For most cases tough, I guess C gets the job done in an acceptable way, not only because it abstracts the CPU at some level, but it can also greatly abstract data through the use of structures and user defined data types. I know you can do all that in asm, but portability and maintenance play a bigger role in most applications nowadays.
>>
>>55418506
A compiler is going to pick up on an unneeded intialization. That's low hanging fruit. GCC and I suspect most compilers give warnings for using an uninitialized variable. It doesn't take much additional code to determine an initialization was unneeded. Even if the compiler missed it, it is an immediate mov instruction which takes one cycle most processors. So if you have a super human user capable of entering data in a microsecond on a machine running at 2GHz you're improving your exection speed by 0.05%.

Assembly might increase your performance significantly if you want to handle huge chunks of data in way that can be improved by using AVX. Otherwise you're probably not going to out think your compiler in a signficant way.
>>
>>55413678
arm isn't terribly hard to work with
x86 is retarded

learned 68k in uni, that's a relatively reasonable architecture

>>55413946
for nearly 99% of modern situations, this is true
doing work on anything chip slower than 12MHz or so, you kind of want to use ASM and tune it as much as you can by hand if speed is of any importance, C's (rather small) overhead becomes an important factor
as an example, you used to be able to tell which games on the Genesis were written in C because they slowed down or didn't run at full framerate (eg, Sonic Spinball)

>>55415750
>didn't log in remotely and use their Windows VMs
I refuse to believe your uni doesn't have this.

also
>too shy to go to computer lab to do work
how the fuck will you manage getting a job when you're done
hell, you just go to the lab and do shit, throw some headphones in your ears, no one looks at you, they're too busy doing work (or fucking around and surfing the internet)
I can understand laziness. I can't understand not just going to the lab and doing your shit if you're actually making the attempt to do the work.

>>55415919
>that there is a point to life
nah
>I shouldn't be depressed.
maybe

>>55415107
I'm curious as to what architectures don't have a C compiler.
And hell, wouldn't satellites and shit be using hardened variants of common, well known ones like x86, 68k, Z80, ARM, etc?
>>
>>55418098
they most likely had to be disassembled, yes
>>
>>55415750
i dropped out of school for a similar reason, except my class had absolutely nothing to do with programming

they never even listed that on the program, it should be illegal
>>
File: WjbwTUH.jpg (931 KB, 1958x2611) Image search: [Google]
WjbwTUH.jpg
931 KB, 1958x2611
>>55418751
crack open some highly optimized binaries sometime and see for yourself some of the low hanging fruit and upper level optimizations that are left out
>>
>>55418824
Real shame was that up until that point, professors preferred we use either OS X or Linux
>>
>>55418756
>I refuse to believe your uni doesn't have this.
They were in the process of getting it. I was part of a citrix beta test or some shit so I could run office ok but that was pretty much it. We had shell accounts on OS X server rigs but that didn't help much lol
>>
>>55418962
huh

honestly, if you weren't going to pirate, you could have installed Windows in a VM, just without a license key (eg, a plain, unmodified Windows image right from Microsoft) -- would have worked enough to do your work, it'll just bitch at you to register
>>
File: output.webm (366 KB, 728x404) Image search: [Google]
output.webm
366 KB, 728x404
Like 6 or 7 years ago I wrote this bootable "OS" in x86 assembly for fun. I learned a lot while writing it, but forgot everything by now.

I made that silly fading out screen in the bootloader after learning that you can change the console palette. I just had to do something with it.
>>
>>55419338
source:
http://pastie.org/private/mmf2oygi1pfvfr6fhxhfng
http://pastie.org/private/cxiiudp9yuvieqm4gpssg

pretty ugly
>>
>>55419338
that fade is hella futuristic
>>
>>55419338
>>55419383
Pretty amazing tbqh senpai
>>
What's so great about FASM?
>>
>>55419338
love the fading effect
>>
>>55413900
Good thing /g/ is abnormal then!

>wait, shit...
>>
>>55418791
That's awesome.
>>
Did I do good, /g/?

.PMODE_ENABLE:
mov eax, cr0 ; Make the perilous journey into protected mode!
or eax, 0x01
mov cr0, eax
jmp 0x08:.JMPLOADER

bits 32 ; This needs to be here so we don't start generating 16 bit code and triple fault! :)
.JMPLOADER:
cli
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov esp, 0x7FFFC ; Stack pointer is right below OSLOADER.EXE
sti

test ecx, ecx
jz .PUSHEAX
push ecx
push edx
jmp .BOOT

.PUSHEAX:
push eax
push ebx


.BOOT:
; At this point, OSLOADER.EXE has been loaded at 0x8000:0000, we now need to calculate where the code (.text)
; section of the binary starts and jump to it.
mov ax, WORD [0x80000]
cmp ax, 0x5A4D ; Compare signature to "MZ"
jne .INVALIDPE
mov eax, 0x80000 + 0x3C ; BX now contains the pointer to the PE header
mov ebx, 0x80000
add ebx, DWORD [eax]
add ebx, 0x28
mov eax, DWORD [ebx]
add eax, 0x80000
mov ebp, eax
xchg bx, bx
call ebp
cli ; Never thought I'd say it, but I miss segment:offset....
hlt
>>
Where do I start with assembly?
Like, where to go for learning and shit.
I'm a beginner but not completely clueless.
>>
>>55421149
google easy6502
>>
>>55418098
Most likely yes, but ever since Adobe started using AMTlib, things got even easier.
Can't remember who the first one to crack it was for the life of me, but I do remember him explaining how the application itself is nothing interesting but the amtlib is the real adventure and once you nail that down it's all easy riding from there.
>>
>>55417654
JS relies on the garbage collector.
>>
>>55413629

Is assembler actually used for anything other than hobbyist stuff now?
>>
>assembly general
>Only 3 people post assembly code
>All 3 of them is fizzbuzz tier code
>Only one person has actually posted something worthwhile they've done with assembly
>Thread full of retards selling, for all practical purposes to 99% of /g/, snakeoil
>All these anonymous faggots bragging for /g/rep

This board is a parody of itself
>>
>>55419113
My computer was too slow for VM, it only had 384 MB RAM
>>
>>55421619
how?
>>55422381
QQ more
>>
>>55422755
they called the other person bitch
>>
>>55415059
Without any optimization I suppose.
>>
>>55422768
it was more in an endearing and teasing erotic way but dude tried to get all superior and aggressive so I just ended it. baka insecure people man
>>
File: image.jpg (38 KB, 370x180) Image search: [Google]
image.jpg
38 KB, 370x180
>>55413629
It's your daily autistic Intel engineer fact!
Intel engineers are always pushing the very limits of the amount of bloat that can be manufactured into one semiconductor device, and 2008 was no exception. The classic
AESKEYGENASSIST
instruction was added to assist with… something. We'll get back to you when we figure it out.
>>
>>55422909
>tfw nobody to disrespect you in an endearing and teasing erotic way
>>
>>55422976
the instruction is pretty self explanatory...
>>
>>55422992
lmao, I'll call you a cock thirsty submissive sissy bitch anon :3
>>
>>55423010
i agree with the other anon thats overdoing it
>>
>>55423133
im sure thats how it comes across to some sensitive people.
>>
>>55414276
Me too anon, also, shameless bump
>>
>>55415059

I severely doubt all satellite firmware is assembly
>>
>>55425408
This.
I know I read a C code standard used by NASA so it can't be the case. At least nowadays.
>>
File: firefox_2016-07-05_18-56-31.png (112 KB, 982x796) Image search: [Google]
firefox_2016-07-05_18-56-31.png
112 KB, 982x796
>>55414040
>Modern compilers are very proformant and out do most humans in most cases of optimization.
hand-optimized assembly is still faster than optimized C(++). But for the vast majority of code it's not feasible to do so(uses too much of the programmers time). Also consider maintainability.
pic relates is sha-1
source: https://www.nayuki.io/page/fast-sha1-hash-implementation-in-x86-assembly
>>
>>55426157
Not usually, no. It'd be an extremely niche case where this is true. Compilers tend to create more performant assembly than a human could produce, in fact.
>>
bomp
>>
>>55413782
A language family
>>
>>55413802
Two uses I can think of:
1. Reverse engineering C programs
2. Optimizing tight inner loops

I'm mostly interested in #1, but you better be thankful for #2 the next time you decode a video on your CPU.
>>
>>55413946
>Ain't application optimization virtually always better handled by whatever compiler you're using? And C overhead is absolutely negligible. Reverse engineering is understandable, but that requires reading the code, not writing it.
If you think so, feel free to recompile ffmpeg with
--disable-asm
and see whether you can still play your Hi10P animes.
>>
File: firefox_2016-07-05_19-12-10.png (5 KB, 237x288) Image search: [Google]
firefox_2016-07-05_19-12-10.png
5 KB, 237x288
>>55426220
no, it's common practice to implement small performance critical parts in assembler, FFMPEG and OpenSSL both do this.
(Intrinsics are arguably assembly not C code)
pic related, FFMPEG has 121 .asm files

https://github.com/openssl/openssl/blob/44c8a5e2b9af8909844cc002c53049311634b314/crypto/aes/asm/aes-ia64.S
even gives reasons as to why compiler-generated code is not an option.
>>
>>55426220
>Compilers tend to create more performant assembly than a human could produce, in fact.
This is false in practice when observing tight loops.

For example, the C implementation of HEVC < intrinsics HEVC primitives < raw assembly HEVC primitives in performance when I benchmarked the three. Some might argue that intrinsics *are* assembly, but the matter of the fact is that the compiler is still in charge of scheduling registers which it often does suboptimally - and FFmpeg's HEVC implementation alone demonstrates this.

Register allocation is an unsolved problem in compilers in practice. (It's NP-complete)
>>
>>55413629
https://en.wikipedia.org/wiki/GNU_MIX_Development_Kit
please port source to MIX/MMIX
because although I do have $7.50 october 1979 MCS-80/85tm FAMILY USER'S MANUAL,
Knuth cannot be wrong about the ideal assembly language for novice users to spend their time upon....

although the illustrated instruction cycles and block diagrams are alluring...
>>
>>55426516
More examples of programs where rewriting the loop in assembly intrinsics sped the implementation up:

https://github.com/SAPikachu/flash3kyuu_deband/blob/master/src/flash3kyuu_deband_impl_c.cpp
vs
https://github.com/SAPikachu/flash3kyuu_deband/blob/master/src/flash3kyuu_deband_sse_base.h

(Feel free to benchmark yourself)
>>
>>55427031
he gave reasonable reasons for chosing his own assembly language
>>
has there been any significant advancement in intel processors since Pentium III?
>>
>>55415788
while my instinctive human feeling is one of sympathy and companionship, I can't help but suspect that you are just another fucking troll, just like almost 'everyone' on the internet and that any time I might invest in this connection would be completely fucking wasted...
>>
>>55422976
i don't understand why they make mnemonics so long today

they're supposed to be short and easy to remember, not like PMOVSXBW

might as well start over
>>
>>55427128
>Assembly language is awesome!
>Discuss.

whereabouts kindfriend did op specify what you state?
>>
>>55427300
knuth did, not op
>>
>>55427197
>they're supposed to be short and easy to remember

Are they?

I mean, for all intents and purposes, most of these opcodes are there simply to be accessible but are never meant for "human" usage.
Instead meant to be used in some special cases that they specify in the manual and the compiler guys have to implement.
>>
>>55427363
fair enough
that being the case why is this thread what it is?
>>
File: 1431659845021.jpg (87 KB, 720x502) Image search: [Google]
1431659845021.jpg
87 KB, 720x502
>>55413733
Who the fuck thought it would be a good idea to have 20 bit address line?
>>
>>55427472
>>>55427128
well the people reading the manuals and writing compilers are probably human aren't they?

otherwise what would be the point of creating 'accessible' opcodes
>>
>>55427197
Most of them follow a pattern. For example, PMOVSXBW is made up of distinct parts:

P-MOV-SX-BW

P refers to packed (SIMD, since it's part of SSE4)
MOV is the instruction (move)
SX refers to sign extend (as opposed to e.g. ZX for zero-extend)
BW is the operand size (byte -> word), and normally omitted when writing assembly

It's so complicated because you have an instruction for virtually every permutation of these parameters. But in reality, you only need to learn the parts in isolation - not all of the combinations.

If anything, they could have improved it by introducing - separators into the actual notation like that.
>>
Can I learn MIPS assembly without knowing any programming languages or should I start with something else?
>>
>>55427472
the opcodes themselves aren't meant for human usage.
the mnemonics, however, are.
you won't find the string "mov" in a binary.
Also, mnemonics are often overloaded sort of like C functions, mov register, immedate and mov register, register can be different opcodes
>>
>>55427546
Also, they're still mnemonics because PMOVSXBW is immediately recognizable and memorable as “packed move sign-extend byte word” to somebody familiar with the format.

However, ask any assembly developer what
66 0f 38 20
means and you'll get a blank stare as a result.
>>
>>55427562
sure, do you have any experience with digital logic or EE?
>>
>>55427586
Not much, I've got a basic understanding
>>
>>55427472

>I mean, for all intents and purposes, most of these opcodes are there simply to be accessible but are never meant for "human" usage.
Instead meant to be used in some special cases that they specify in the manual and the compiler guys have to implement.

So, for human usage.

GP is right, it's silly to make such cryptic mneumonics.

Then again, they're often operations that do pretty convoluted stuff, so I'm not sure how much clearer they could be.
>>
>>55427562
That's trivially “yes” since everybody who knows MIPS, at some point in their lives, did not know any programming languages.
>>
>>55427517
people trying to work around limitations of the hardware available at the time.

https://en.wikipedia.org/wiki/Real_mode
>>
what program do I use to assemble MIPS ASM in Linux?
>>
>>55427932
I'm pretty sure you could compile the GNU binutils to target MIPS.

Make sure to keep all that stuff in a separate prefix if you do.
>>
>>55427680
how much do you know?
not enough to make it count at this point in time, I am afraid.
>>
>>55428044
So I used as to assemble it with the mips32 flag, file says it's a mips32 elf but I get an error trying to execute it saying
./hw: not executable: 32-bit ELF file
>>
>>55414003
https://pacman128.github.io/pcasm
>>
>>55428782
did you chmod +x it?
>>
>>55429476
Yeah
% chmod +x hw 
[ci20:~] gareh% file hw
hw: ELF 32-bit LSB relocatable, MIPS, MIPS32 version 1 (SYSV), not stripped
[ci20:~] gareh% ./hw
mksh: ./hw: not executable: 32-bit ELF file
>>
>>55429524
this is an issue with an arch not being supported by the OS, I think. IIRC, this used to happen in ubuntu/debian when you didn't have the multiarch libs.
>>
>>55430864
Shouldn't a MIPS32 OS support a MIPS32 binary?
>>
>>55430919
yeah, but something is wrong with your binary.
what compiler are you using, and how are you compiling the program? note that you can't just cross compile using the "normal" toolchain plus some flags, you have to install libs and stuff. also, even then, some things depend on the OS, unless the binary is statically(?) linked
>>
>>55431041
as -mips32 hw.s -o hw

How should I be doing it? And isn't cross compiling only a thing when you're compiling for a different architecture? I'm working on the system I want to execute the program on, so the compiler should have no issues churning out compatible binaries, shouldn't it?
>>
>>55431121
don't you need to use the linker, too? or is that just with nasm
>>
>>55431142
I've got no clue
>>
File: image.jpg (22 KB, 485x303) Image search: [Google]
image.jpg
22 KB, 485x303
Why does most MBR bootstrap code load the second-stage at 0x600 instead of 0x500? I know the DOS bootloader had a reason but why do newer ones do it?
>>
>>55428782
Guessing here but it's probably an ELF object rather than an ELF executable.
>>
>>55426157
top notch code on that page.
>>
>>55431233
yeah so if that's the case he needs to use ld, right?
>>
>>55431315
Yep
>>
>>55431365
So what do I with ld?
>>
Honestly, the plebs in here thinking they are so fucking smart.

>not programming in machine code
>>
>>55427148
Ladies and /g/ents, neo-/g/
>>
>>55431377
Assuming your ld targets MIPS32, and you're not calling any external functions:
ld -o hwx hw
>>
>>55431485
It just says
Illegal instruction
when I try to run it
>>
I'm honestly surprised this thread has no shitposting
>>
>>55431617
see >>55431398
>>
>>55431617
That's just due to your definition of shitposting.
>>
>>55431398
I bet you can't even write a "Hello World" in machine code.
Thread replies: 255
Thread images: 26

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.