[SOLVED] .globl copy

$25

File Name: .globl copy.zip
File Size: 103.62 KB

5/5 - (1 vote)

.globlcopy
copy:
# A in rdi, C in rsi, N in edx
xorl %eax, %eax# set eax to 0
# since this function is a leaf function, no need to save caller-saved registers rcx and r8
xorl %ecx, %ecx# row number i is in ecx -> i = 0

# For each row
rowLoop:
movl $0, %r8d# column number j in r8d -> j = 0
cmpl %edx, %ecx# loop as long as i N < 0jge doneWithRows# For each cell of this rowcolLoop:cmpl %edx, %r8d# loop as long as j – N < 0jge doneWithCells# Compute the address of current cell that is copied from A to C# since this function is a leaf function, no need to save caller-saved registers r10 and r11movl %edx, %r10d# r10d = N imull %ecx, %r10d# r10d = i*Naddl %r8d, %r10d# j + i*Nimull $1, %r10d # r10 = L * (j + i*N) -> L is char (1Byte)
movq %r10, %r11# r11 = L * (j + i*N)
addq %rdi, %r10# r10 = A + L * (j + i*N)
addq %rsi, %r11# r11 = C + L * (j + i*N)

# Copy A[L * (j + i*N)] to C[L * (j + i*N)]
movb (%r10), %r9b # temp = A[L * (j + i*N)]
movb %r9b, (%r11) # C[L * (j + i*N)] = temp

incl %r8d# column number j++ (in r8d)
jmp colLoop# go to next cell

# Go to next row
doneWithCells:
incl %ecx# row number i++ (in ecx)
jmp rowLoop# Play it again, Sam!

doneWithRows:# bye! bye!
ret

#####################
.globltranspose
transpose:

ret

#####################
.globlreverseColumns
reverseColumns:

ret

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] .globl copy
$25