板凳——————————————————(枯藤 )MIX汇编 前导(6)

//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 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值