School Commit Init
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
bits 32 ; assembling for the 32 bits architecture
|
||||
|
||||
; declare the EntryPoint (a label defining the very first instruction of the program)
|
||||
global start
|
||||
|
||||
; declare external functions needed by our program
|
||||
extern exit,scanf ; tell nasm that exit exists even if we won't be defining it
|
||||
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
|
||||
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
|
||||
import scanf msvcrt.dll
|
||||
|
||||
;Read two numbers a and b (in base 10) from the keyboard and calculate their product. This value will be stored in a variable called "result" (defined in the data segment).
|
||||
|
||||
|
||||
segment data use32 class=data
|
||||
query db "%d",0
|
||||
a dd 0
|
||||
b dd 0
|
||||
result dq 0
|
||||
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
; ...
|
||||
push dword a
|
||||
push dword query
|
||||
call [scanf]
|
||||
add ESP,4*2
|
||||
|
||||
push dword b
|
||||
push dword query
|
||||
call [scanf]
|
||||
add ESP,4*2
|
||||
|
||||
mov EAX,[a]
|
||||
imul dword [b]
|
||||
mov [result],EAX
|
||||
mov [result+4],EDX
|
||||
; exit(0)
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
|
||||
|
||||
import socket
|
||||
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||
msg="hey"
|
||||
sleep(10)
|
||||
s.sendto(str.encode(msg),("127.0.0.1",5555))
|
||||
msg,adr=s.recvfrom(10)
|
||||
print (msg.decode())
|
||||
@@ -0,0 +1,47 @@
|
||||
bits 32 ; assembling for the 32 bits architecture
|
||||
|
||||
; declare the EntryPoint (a label defining the very first instruction of the program)
|
||||
global start
|
||||
|
||||
; declare external functions needed by our program
|
||||
extern exit,scanf,printf ; tell nasm that exit exists even if we won't be defining it
|
||||
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
|
||||
import scanf msvcrt.dll
|
||||
import printf msvcrt.dll
|
||||
|
||||
; our data is declared here (the variables needed by our program)
|
||||
|
||||
;Read two numbers a and b (in base 10) from the keyboard. Calculate and print their arithmetic average in base 16
|
||||
|
||||
segment data use32 class=data
|
||||
read_query db "%d",0
|
||||
write_query db "The arithmetic average in base 16 is: 0x%08X",0
|
||||
a dd 0
|
||||
b dd 0
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
; ...
|
||||
push dword a
|
||||
push dword read_query
|
||||
call [scanf]
|
||||
add ESP,4*2
|
||||
|
||||
push dword b
|
||||
push dword read_query
|
||||
call [scanf]
|
||||
add ESP,4*2
|
||||
|
||||
mov EAX,[a]
|
||||
add EAX,[b]
|
||||
sar EAX,1
|
||||
|
||||
push EAX
|
||||
push write_query
|
||||
call [printf]
|
||||
add ESP, 4*2
|
||||
|
||||
; exit(0)
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
Reference in New Issue
Block a user