Last active
December 25, 2015 21:49
-
-
Save vertexclique/7044869 to your computer and use it in GitHub Desktop.
Comp. Arch. hw.4Write a full program that add two 8 byte numbers and store result in 8 byte reserved memory location, called R.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// bwdaddbuff.s | |
// bwdaddbuff | |
// | |
// Created by Mahmut Bulut on 10/11/13. | |
// Copyright (c) 2013 Mahmut Bulut. All rights reserved. | |
// | |
#.intel_syntax | |
.data # .data segment | |
# Exemplary extra data set | |
# N1: .quad 0x11, 0x48, 0x23, 0x12, 0x71, 0x10, 0x47, 0x08 | |
# N2: .quad 0x22, 0x43, 0x86, 0x92, 0x03, 0x05, 0x30, 0x82 | |
N1: .byte 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 | |
N2: .byte 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 | |
# Addition of N1 and N2 results in ABCDEFGH | |
R: .fill 8, 1, 0x00 # Zero fill | |
.text # .text segment | |
.globl _main | |
_main: | |
pushl %ebp # push the stack base pointer reg to stack itself | |
movl %esp, %ebp # move top stack pointer to base stack pointer to make it fillable | |
subl $24, %esp # system call function stack resize | |
movw $2, %cx # count register fill | |
iter: # iteration declaration | |
movl N1, %eax # target data move | |
movl N2, %ebx # addition data move | |
addl %ebx, %eax # add | |
movl %eax, R # copy to result | |
movl $R, (%esp) # Result to stack pointer for usage puts | |
cmpw $1, %cx # just for tests nothing so much | |
je next4 | |
next4: | |
movl (N1)+4, %eax # next 4 bytes | |
movl (N2)+4, %ebx | |
addl %ebx, %eax | |
movl %eax, (R)+4 # fill next 4 bytes | |
movl $R, (%esp) | |
loop iter # loop is just for example it is not needed | |
call _puts # print the stack segment pushed in with _puts | |
xorl %eax, %eax # clear eax | |
leave | |
ret | |
.subsections_via_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment