TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Write assembly that opens each file in a dir and changes foo with bar

3 点作者 frogger8超过 2 年前
Write an assembly program that opens each file in a directory and then changes all of the occurences of foo with bar.<p>;Open a file handle<p>mov ax, 3Dh<p>mov dx, offset filename<p>int 21h<p>;Check that the file handle is valid<p>cmp ax, 0<p>jne file_open<p>;Start looping through the directory<p>mov si, offset directory<p>mov di, offset filename<p>loop:<p>mov al, [si]<p>cmp al, 0<p>je exit<p>;Copy the filename<p>mov [di], al<p>inc si<p>inc di<p>jmp loop<p>file_open:<p>;Read the file and search for &quot;foo&quot;<p>mov bx, ax<p>mov ah, 3Fh<p>mov cx, 0FFFFh<p>mov dx, offset buffer<p>int 21h<p>;Check if the end of file has been reached<p>cmp ax, 0<p>je exit<p>;Loop through the read buffer<p>mov si, offset buffer<p>mov di, offset replace<p>loop2: mov al, [si] cmp al, &#x27;f&#x27; je check_foo inc si jmp loop2<p>check_foo: cmp byte [si + 1], &#x27;o&#x27; jne loop2 cmp byte [si + 2], &#x27;o&#x27; jne loop2<p>;Replace &quot;foo&quot; with &quot;bar&quot; mov [di], &#x27;b&#x27; inc di mov [di], &#x27;a&#x27; inc di mov [di], &#x27;r&#x27; inc di jmp loop2<p>;Write the modified buffer to the file mov bx, ax mov ah, 40h mov cx, 0FFFFh mov dx, offset replace int 21h<p>;Go to the next file jmp file_open<p>exit: ;Close the file mov ah, 3Eh int 21h<p>;Exit mov ax, 4C00h int 21h

1 comment

frogger8超过 2 年前
OP here, I asked… even chatGPT doesn’t know how to make the new lines format properly on HN :)