//2019年天津大学智算学部汇编语言程序设计-李罡
//2020年08月09日 15时05分15秒
The direction depends on DF, if DF = 1 they decrease
cld # clear the DF (= 0), increase
std # set the DF (= 0), decrease
.section .data
value1:
.ascii “This is a test string.\n”
.section .bss
.lcomm output, 23
.section .text
.globl main
main:
leal value1, %esi
leal output, %edi
movl $23, %ecx
cld
loop1: # 第一种
movsb
loop loop1
rep movsb # 第二种
Using rep prefix to transfer string by bytes.
ECX is used to count the loop.
movl $1, %eax
movl $0, %ebx
int $0x80
#rep prefix to ransfer by blocks
# Eg. to transfer 8 bytes, when using movsb, ecx should be 8.
# If using movsw, ecx is set to 4
# Pay attention to out-of-boundary
# Eg. String length is 23 bytes. If ecx = 6, using movsl
# will transfer 24 bytes.
(gdb) x/s &output
#ox601058 : “This is a test string.\nO”
.section .data
value1:
.ascii “This is a test string.\n”
value2:
.ascii “Oops”
.section .bss
.lcomm output, 23
.section .text
.globl main
main:
leal value1, %esi
leal output, %edi
movl $6, %ecx
cld
rep movsl
movl $1, %eax
movl $0, %ebx
int $0x80
/*
wannian07@wannian07-PC:~$ gcc hello.s -o hello
wannian07@wannian07-PC:~$ ./hello
wannian07@wannian07-PC:~$
#2020年08月09日 15时31分10秒
.section .data
string1:
.ascii “This is a test of the conversion program!\n”
length:
.int 43 # length = .-output 计算长度
divisor: # 除法 %4
.int 4
.section .bss
.lcomm buffer, 43
.section .text
.globl main
main:
leal string1, %esi
leal buffer, %edi
movl length, %ecx # ecx