Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "mov"
-
#Programming alone
print "Hello World!"
#Programming while someone watches
global _start
section .data
msg db "Hello, World!", 10
len equ $ - msg
section .text
_start:
mov rax, 4
mov rbx, 1
mov rcx, msg
mov rdx, len
int 0x80
mov rax, 1
mov rbx, 0
int 0x805 -
ORG 0000H
MOV R0,#00H
MOV R1,#50H
MOV R2,#00H
MOV R3,#60H
MOV R4,#05H
MOV DPL,R0 LOOP:
MOV DPH,R1
MOVX A,@DPTR
CPL A
MOV DPL,R2
MOV DPH,R3
MOVX @DPTR,A
INC R0
INC R2
DJNZ R4,LOOP
END9 -
section .text
global _start
section .data
msg db 'Hello, world!',0xa
len equ $ - msg
section .text
_start:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
mov ebx,0
mov eax,1
int 0x803 -
Hoozay! I'm now starting to become an adult! (or atleast, that's what they expect of me)
myAge:
.long 19
main:
push rbp
mov rbp, rsp
mov eax, DWORD PTR myAge[rip]
add eax, 1
mov DWORD PTR myAge[rip], eax
mov eax, DWORD PTR myAge[rip]
mov esi, eax
mov edi, OFFSET FLAT:_ZSt4cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov eax, 0
pop rbp
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L5
cmp DWORD PTR [rbp-8], 65535
jne .L5
mov edi, OFFSET FLAT:_ZStL8__ioinit
call std::ios_base::Init::Init() [complete object constructor]
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:_ZStL8__ioinit
mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
call __cxa_atexit
.L5:
nop
leave
ret
_GLOBAL__sub_I_myAge:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret12 -
!rant
Just overheard a senior engineer say to a junior "I dont tell you to move, I tell you to MOV because you're as stupid as a computer" wow that hurt8 -
section .text
global _start
_start:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
mov eax,1
int 0x80
section .data
msg db 'Yo Mama So Fat',0xa
len equ $ - msg7 -
So recently I did a lot of research into the internals of Computers and CPUs.
And i'd like to share a result of mine.
First of all, take some time to look at the code down below. You see two assembler codes and two command lines.
The Assembler code is designed to test how the instructions "enter" and "leave" compare to manually doing what they are shortened to.
Enter and leave create a new Stackframe: this means, that they create a new temporary stack. The stack is where local variables are put to by the compiler. On the right side, you can see how I create my own stack by using
push rbp
mov rbp, rsp
sub rsp, 0
(I won't get into details behind why that works).
Okay. Why is this even relevant?
Well: there is the assumption that enter and leave are very slow. This is due to raw numbers:
In some paper I saw ( I couldn't find the link, i'm sorry), enter was said to use up 12 CPU cycles, while the manual stacking would require 3 (push + mov + sub => 1 + 1 + 1).
When I compile an empty function, I get pretty much what you'd expect just from the raw numbers of CPU cycles.
HOWEVER, then I add the dummy code in the middle:
mov eax, 123
add eax, 123543
mov ebx, 234
div ebx
and magically - both sides have the same result.
Why????
For one thing, there is CPU prefetching. This is the CPU loading in ram before its done executing the current instruction (this is how anti-debugger code works, btw. Might make another rant on that). Then there is the fact that the CPU usually starts work on the next instruction while the current instruction is processing IFF the register currently involved isnt involved in the next instruction (that would cause a lot of synchronisation problems). Now notice, that the CPU can't do any of that when manually entering and leaving. It can only start doing the mov eax, 1234 while performing the sub rsp, 0.
----------------
NOW: notice that the code on the right didn't take any precautions like making sure that the stack is big enough. If you sub too much stack at once, the stack will be exhausted, thats what we call a stack overflow. enter implements checks for that, and emits an interrupt if there is a SO (take this with a grain of salt, I couldn't find a resource backing this up). There are another type of checks I don't fully get (stack level checks) so I'd rather not make a fool of myself by writing about them.
Because of all those reasons I think that compilers should start using enter and leave again.
========
This post showed very well that bare numbers can often mislead.21 -
my teacher genuinely asked the class, which one is better GUI or CLI? everyone said GUI except me, he asked why? (the reason he was expecting from me was something different) i said, "CLI differentiate us from those who just click and realise that how simple is this to operate and why are we being heavily paid?"1
-
The best/worst code comments you have ever seen?
Mine:
//Upload didn't work, have to react:
system.println('no result');
//$Message gives out a message in the compiler log.
{$Message Hint 'Feed the cat'}
//Not really needed
//Closed source - Why even comments?
//Looks like bullshit, but it has to be done this way.
//This one's really fucked up.
//If it crashes, click again.
asm JMP START end; //because no goto XP
catch {
//shit happens
}
//OMG!!! And this works???
asm
...
mov [0], 0 //uh, maybe there is a better way of throw an exception
...
mov [0], 0 //still a strange way to notify of an error
// this makes it exiting -- in other words: unstable !!!!!
//Paranoic - can't happen, but I trust no one.
else {
//please no -.-
sleep(0);
}
//wuppdi
for (int i = random(500); i < 1000 + random(500 + random(250)); i++)
{
// Do crap, so its harder to decompile
}
//This job would be great if it wasn't for the f**king customers.
//TODO: place this peace of code somewhere else...
// Beware of bugs in the code above; I have only proved it correct, not tried it.
{$IFDEF VER93}
//Good luck
{$DEFINE VER9x}
{$ENDIF}
//THIS SHIT IS LEAKING! SOMEONE FIX IT! :)
/* no comment */5 -
If writing caption for your Instagram picture is an art, then what is commit messages for your GitHub repositories.5
-
I remembered one time my freakin prof in programming taugh us how to understand computer language, that time my worst enemy is ASSEMBLY, for some reasons my teacher doesn't know how to code in assembly like wtf?
On our last grading period he asked us to create a program using mov and shift and the deadline is set tomorrow after he announced it.
I remember my code in that freaking subject
MOV COURSE
SHIFT SCHOOL
HAHAHAHA after that I was scolded big time 😂 -
We had a project with a web app and an Android app. We split it out, he took the web and I was working on Android. He was very curious to do the project with me and very motivated at the beginning. We agreed on our first module that was user authentication. After some time when I told him that first module of app is ready and asked him on his progress, (When ever we had a talk he pretend like every thing is going fluently, though I continously told him ask for help if needed ) he opened a folder in vs code containing two files "index.html" and "style.css" and showed me the "login & sign up" design he was doing for days. I have no option but to appreciate his work. On that day I created new folder on my machine "web application" and started working.3
-
Dammit! I don't know how many times I've typed "mov x y" in my terminal tonight...
I finally gave in and set an alias for it.
Damned x86 assembly... -
I use spaces instead of tabs. Working beside me, my mates were irritated of that beautiful sound(they called it noise) from my keyboard.4
-
I'm delirious so here's your daily dose of fuck:
```fasm
; --- * --- * ---
; 64-bit byte-by-byte mash
macro clamp_u8 {
mov cl,$08;
mov rdx,rax;
rept 8 \{
rol rdx,cl;
xor al,dl;
\};
};
; --- * --- * ---
; give 8-bit random seed
macro prng_u8 {
rdtsc;
shl rdx,32;
or rax,rdx;
clamp_u8;
};
; --- * --- * ---
; roll dice
d20: prng_u8;
; x%20, according to gcc ;>
mov edi,eax;
mov eax,-51;
mul dil;
shr ax,12;
lea eax,[rax+rax*4];
lea edx,[0+rax*4];
mov eax,edi;
sub eax,edx;
; discard high and give
and rax,$FF;
ret;
```
I guess `d20` could be inlined too but I thought it'd be too much.
Is it faster than straight C? Probably not. But it's way lighter, so it loads faster. Below five hundred bytes mother fucker.
Now if you'll excuse me, I'll go sit in the darkness repeteadly typing roll 1d20 on the terminal. For reasons.9 -
mov al, [var]
var db 07h
Error on line 1: undefined operation size.
Silly me defining a byte, using mov on a byte-wide register with said byte-wide variable. What size it could be, the byte-wide variable is soo fucken unknown i'm so sorry.1 -
Ok It's my last term in CS and guess what I have the knowledge as same as some one in high school i rly don't know what to do nAw any suggestions17
-
The rear ducking continues. We've built a reliable translator in the dumbest fucking way possible, it's just lovely. I simply reused the structure for feeding data to the VM assembler, an array of arrays, where there's one array of (ins [args]) per node in the parse tree.
It's nice because nodes can be solved out of order without affecting the actual sequence in which the instructions are output. And if one statement (node) equals multiple instructions, you just push multiple entries to the corresponding array, or push nothing if you need to output nothing. Easy as goblin pie.
This is enough to convert an input language to the assembly-like intermediate representation we use for the virtual machine. So then there's doing it backwards: walk the same array of arrays, and map those virtual instructions to a physical architechture. I guess I could do the encoding to native binary myself, it'd certainly be interesting to try, but I'm burnt-out already so I'll just use fasm for now.
Initial test: wrote a test program in my own stupid language, ran the translator, dump output to file, assemble that with fasm, run with r2 -d.
Crashes? No.
Runs fine? Yes and no.
For fuck's sake, I don't have syscalls. Mainly because the VM doesn't have an operating system, lmao. I was testing virtual programs by just freezing state, terminating, then dumping the fucking registers and stack to the console, we have no I/O to speak of. Not even a real 'exit', VM handles that by reading a return value every step like a mentally damaged son of a bitch.
So anyway, I manually paste the linux mambo, you know:
mov rax,60
mov rdi,0
syscall
And NOW our program can end execution without crashing.
Okay then, so does the test code work correctly?
** DRUM ROLL **
Yes.
Ladies and gentlemen, mother fucking PESO is now a compiled language, and going forward I will be expectantly receiving your marriage proposals for reviewing. Oh, but not so fast, we still need a frontend...
Well, we'll handle that in the next few days. I'm just glad to be *nearly* finished with this fucking compiler, I want nothing to do with anything else ever, but we know that's not going to happen, so Lord please end my pain.
No sponsor as this rant has been paid for by tax evasion. -
Any NODE-JS.pdf available to learn a bit deeper.
Links would be great.
Names, if you've downloaded before.
Thanks in advance.12 -
Brrruh "mov" only works when both registers have the same size.
Could've told me this beforehand dude.5 -
Little addition on my rant about the enter and leave instructions being better than push mov sub for stackframes:
I had that debate with a friend of mine, who tried the same code ... and failed to get enter to be as fast. Infact, for him, enter was twice as slow, on his older computer even 3times as slow.
Mhh... pretty bad. basically blows up my whole point.
I tried the code on my computer... Can't reproduce the error.
Weird.
"Which CPU are you on?"
>"I'm on Intel"
Both of his computers are on intel. I use an amd ryzeni1600. Now this might be a bit of a fast conclusion, but I think that its safe to say that intel should atleast do better for SOME parts of their CPUs.9 -
So I have an array of length 20 which stores a 64 bit decimal number by digits. The starting address is let's say array64. When I am trying to build up my number in ECX:EBX, I am using EDX as the iterator to access the individual elements of the array (I am loading them into AL)
.LOOP:
....
MOV AL, [array64+EDX]
INC EDX
....
JMP .LOOP
The problem is: somehow EDX cannot get higher than 10, so the program just stops and waits for input, when I try to work with a 12 digit number...
This module is outside the main function, and I thought about some Far Pointer problems, but all of my ideas just failed...
What is wrong here?1 -
```
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!', 0xa ;string to be printed
len equ $ - msg ;length of the string
```
I've never seen such a terrible way to print "hello world"8 -
Does anyone know which bytes represent
mov rcx, 0x7FF0000000 (some qword)
mov rdx, 0x12345678 (some dword)
?
Or where I can find this?4 -
section .data
msg: db "ASM, Love Or Hate?",10
msglen: equ $-msg
GLOBAL _start
_start:
mov rdx, [msg]
mov rdi, msglen
call print_stdout
mov rax, 0x3c
mov rdi, 0
syscall
print_stdout:
mov rax, SYS_WRITE
mov rdi, STDOUT
syscall
ret5 -
VESA is driving me crazy.
I'm trying to set my video mode via VESA functions which works, the QEMU window size changes, ton of more space.
Problem now however is that I have no idea where in the name of god the goddamn framebuffer starts.
Apparently it's address is located withing the mode info block which I have successfully queried and stored in ES:DI.
Problem now is getting this info block into my 32-bit kernel.
I tried smacking it on the stack which only produces hot garbage.
Essentially it goes like this
[...make sure pointer to block is stored within ES:DI...]
mov ebx, [ES:DI]
[Switch to 32 bit mode, ebx is not erased by doing so]
;Set up stack
mov ebp, 0x90000
mov esp, ebp
call kernel_main
jmp $
kernel_main takes this pointer as an argument, hence why I've pushed it onto stack:
main(uint32_t *ptr);
When I try accessing it however by doing the following:
vbe_mode_info_block* info_block = (vbe_mode_info_block)ptr;
And then try accessing the in the member 'framebuffer' using 'info_block->framebuffer' it's giving me hot garbage.
I'm probably doing something obvious wrong.
Frustrating.
I'm gonna try passing ES and DI seperately and converting them to a real mode address by doing addr = (ES*0x10)+DI;
MAYBE MAYBE MAYBE2 -
Those who know x86 assembly and real mode, what'd I do wrong here?
mov cx,0000
.loop
mov ax,e823
mov bx,1
add cx,1
int 15 ; supposed to be undocumented CMOS raw write on my mobo if bx!=0,ax=e823
test cx,00ff
jne .loop
ret
The JNE doesn't ever trigger, so I end up always returning no matter what cx is. I'm testing if the undocumented writes actually work, and cl is supposed to be 00-FF as it's the address to write bx to in CMOS. I'm running in real mode, if it matters.8 -
Problem: in assembler, i want to proceed an string byte by byte. How can i do this?
My try:
Mov ebx, 0
S:
Mov eax, [var +ebx]
;somethin
Add ebx, 1
Jmp s
But it doesnt cut off the thing rigth8 -
Does master degree really matter or if I take some courses will be better if I'll not go through academic life10