What's new

Help Patulong po IT peepz sa Assembly Language?

blackbox9081

Eternal Poster
Established
Write an assembly language program that adds two 32-bit numbers and stores the result at memory location GAMMA.
The first 32-bit number is located at memory location ALPHA. while the second 32-bit number is located at
memory location BETA.

ALPHA: 7856_3412
BETA: 1122_EEFF
GAMMA: 8979_2311
 
Here's an assembly language program that adds two 32-bit numbers and stores the result at memory location GAMMA:

Code:
section .data
ALPHA dd 78563412h     ; first 32-bit number
BETA dd 1122EEFFh     ; second 32-bit number
GAMMA dd 89792311h    ; result

section .text
global _start

_start:
    ; load the first number into EAX
    mov eax, [ALPHA]

    ; add the second number to EAX
    add eax, [BETA]

    ; store the result in GAMMA
    mov [GAMMA], eax

    ; exit the program
    mov eax, 1      ; system call to exit
    xor ebx, ebx    ; return code 0
    int 0x80        ; invoke the operating system

In this program, we first define the memory locations ALPHA, BETA, and GAMMA using the dd (define doubleword) directive. We then define the _start label and begin the program execution.

Inside the _start block, we first load the first 32-bit number from ALPHA into the EAX register using the mov instruction. We then add the second number from BETA to EAX using the add instruction.

Finally, we store the resulting sum back into GAMMA using the mov instruction. This completes the addition operation and we exit the program using the mov, xor, and int instructions.

After executing the program, the value stored at memory location GAMMA should be 89792311h.
 
Galing neto. Para na to sa mga may assignment na nagpapagawa ng code sa iba. Ida-daan na lang sa bot para meron na silang sagot at may explanation pa. Mas mapapadali nila ang self learning niyan in a positive side.
 

Similar threads

Back
Top